What is causing PDO error Cannot execute queries while other unbuffered queries are active?

前端 未结 4 662
野的像风
野的像风 2021-02-01 09:01

I have the following code:

$dbh = new PDO(\"mysql:host=$host;dbname=$dbname\", $user, $pass);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->         


        
4条回答
  •  攒了一身酷
    2021-02-01 09:26

    Oddly enough, the PHP packages provided by Ubuntu are not compiled with the Mysql native driver, but with the old libmysqlclient instead (tested on Ubuntu 13.10 with default packages):

    getAttribute(PDO::ATTR_CLIENT_VERSION); // prints "5.5.35", i.e MySQL version
    // prints "mysqlnd (...)" when using mysqlnd
    

    Your very test case ("Edit 4", with setAttribute(MYSQL_ATTR_USE_BUFFERED_QUERY, true)) works as expected with PHP 5.5.3 manually compiled with mysqlnd with:

    ./configure --with-pdo-mysql=mysqlnd # default driver since PHP v5.4
    

    ... but fails with:

    bash> ./configure --with-pdo-mysql=/usr/bin/mysql_config
    

    It quite odd that it fails only if the first statement is executed twice; this must be a bug in the libmysqlclient driver.

    Both drivers fail as expected when MYSQL_ATTR_USE_BUFFERED_QUERY is false. Your Common Sense already demonstrated why this is expected behaviour, regardless of the number of rows in the result set.

    Mike found out that the current workaround is installing the php5-mysqlnd package instead of the Canonical-recommended php5-mysql.

提交回复
热议问题