PDO::MYSQL_ATTR_INIT_COMMAND 似乎打破了查询,尝试你自己的。
以下:
$connection = new \PDO("mysql:host=localhost;dbname=php_orm_test", "dev", "dev",[
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8; SET CHARACTER SET UTF8; SET character_set_connection=UTF8; SET character_set_client=UTF8;"
]);
$statement = $connection->prepare("describe users");
$statement->execute();
$statement->fetchAll(\PDO::FETCH_ASSOC);
var_dump($statement->errorInfo());
$statement->closeCursor();
抛出:
array(3) {
[0]=>
string(5) "00000"
[1]=>
int(2014)
[2]=>
string(269) "Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute."
}
如果我删除 MYSQL_ATTR_INIT_COMMAND 一切正常...任何想法?
请注意,即使这也不起作用......
PDO::MYSQL_ATTR_INIT_COMMAND => self::DRIVER_INIT,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true