の定数「MYSQL_ATTR_INIT_COMMAND」私はmysql
データベースとラチェットを接続しようとしているが、私はこのerorr を取得し、私はXAMPPのphpmyadminのを使用してMySQLを実行してからデータを送信する前に、私はconnectToDB.phpファイル内のコードを使用htmlフォームをPHPを使用してSQL行に変換したところOK となりました。コードをChat.php
でテストしたところ、sql行を追加する前にコードがテストされていましたが、うまくいきましたが、chat.phpのconnectToDB.php行を追加した後、プロンプト? php.iniファイルで エラーラチェットPHPの致命的なエラー:未定義のクラス
PHP Fatal error: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in htdocs/connectToDB.php on line 19
connectToDB.php
コード
<?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());
}
?>
Chat.php
ファイルコード
<?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();
}
}
@rafidはどのセクションですか? [pdo]、[pcre]などのようなセクションがあります。 私はそれを追加する必要がありますか? – shar
xamppのコントロールパネルに移動し、 'config'ボタンをクリックして' php.ini'ファイルを開き、 'php_pdo_mysql'を検索して'; 'を' php_pdo_mysql'の前に削除して保存します。その後、Apacheを再起動してコードを試してください –