ratchet PHP致命错误:未定义的类常量';MYSQL_ATTR_INIT_命令';在里面

ratchet PHP致命错误:未定义的类常量';MYSQL_ATTR_INIT_命令';在里面,php,mysql,sql,database,websocket,Php,Mysql,Sql,Database,Websocket,我试图将ratchet连接到mysql数据库,但我得到了这个erorr 我使用xampp phpmyadmin运行mysql,之前我使用connectToDB.php文件中的代码,使用php将数据从html表单发送到sql行,这一切正常 在添加sql行之前,我测试了Chat.php文件中的代码,效果很好,但是在Chat.php中添加了connectToDB.php行之后,我得到了这个错误,那么问题出在哪里呢? 错误 PHP致命错误:未定义的类常量“MYSQL\u ATTR\u INIT\u CO

我试图将ratchet连接到mysql数据库,但我得到了这个erorr 我使用xampp phpmyadmin运行mysql,之前我使用connectToDB.php文件中的代码,使用php将数据从html表单发送到sql行,这一切正常 在添加sql行之前,我测试了
Chat.php
文件中的代码,效果很好,但是在Chat.php中添加了connectToDB.php行之后,我得到了这个错误,那么问题出在哪里呢? 错误

PHP致命错误:未定义的类常量“MYSQL\u ATTR\u INIT\u COMMAND” 在第19行的htdocs/connectToDB.php中

connectToDB.php
code

<?php
if(!session_id()) session_start();



/* $dbhost  = 'localhost';
//$dbname       = '1852132_ch';
//$dbuser       = 'root';
//$dbpass       = ''; */

$dbhost     = "localhost";
$dbname     = "test";
$dbuser     = "root";
$dbpass     = "";

// database connection
try{
    $_db = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass, array(
                    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", 
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                    PDO::ATTR_PERSISTENT => true
                )); 
}catch(Excepion $e){
    die("ERROR : ".$e->getMessage());
}
?>

在php.ini文件中,应该有以下行(未注释):


然后重新启动apache并在任何部分中尝试您的代码

@rafid?有[pdo]、[pcre]等部分。。我应该在其中任何一个中添加它?转到xampp控制面板,单击
config
按钮,打开`php.ini`文件,搜索
php_pdo_mysql
并删除
在php_pdo_mysql之前保存。然后重新启动apache并尝试您的代码
<?php
namespace MyApp;

include('/opt/lampp/htdocs/ww/classes/user.php');
include('/opt/lampp/htdocs/ww/connectToDB.php');

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {
    protected $clients;

    public function __construct() {
        $this->clients = new \SplObjectStorage;
    }

    public function onOpen(ConnectionInterface $conn) {
        // Store the new connection to send messages to later
        $this->clients->attach($conn);

        echo "New connection! ({$conn->resourceId})\n";
        $sql = $_db->query("UPDATE users SET userid= '1999' WHERE UserName='batman'");

    }

    public function onMessage(ConnectionInterface $from, $msg) {
        $numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
            , $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');

        foreach ($this->clients as $client) {
            if ($from !== $client) {
                // The sender is not the receiver, send to each client connected
                $client->send($msg);
            }
        }
    }

    public function onClose(ConnectionInterface $conn) {
        // The connection is closed, remove it, as we can no longer send it messages
        $this->clients->detach($conn);

        echo "Connection {$conn->resourceId} has disconnected\n";
    }

    public function onError(ConnectionInterface $conn, \Exception $e) {
        echo "An error has occurred: {$e->getMessage()}\n";

        $conn->close();
    }
}
extension=php_pdo_mysql.dll on Windows
extension=php_pdo_mysql.so on Linux/Mac