Bug #70066 [Ver->Csd]: Unexpected "Cannot execute queries while other unbuffered queries"
| From: | nikic@php.net | Date: | Wed, 09 Dec 2020 16:25:31 +0000 |
| Subject: | Bug #70066 [Ver->Csd]: Unexpected "Cannot execute queries while other unbuffered queries" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-230968@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70066&edit=1
ID: 70066
Updated by: nikic@php.net
Reported by: david at grudl dot com
Summary: Unexpected "Cannot execute queries while other
unbuffered queries"
-Status: Verified
+Status: Closed
Type: Bug
Package: PDO MySQL
PHP Version: 5.6.11
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=106e7e4bca7c0fd975eb219b18e3c34957ba8657
Log: Fixed bug #70066
Previous Comments:
------------------------------------------------------------------------
[2020-12-09 16:06:55] nikic@php.net
The relevant part here is that "USE" is not supported by prepared statements. MySQL
returns error 1295 and PDO checks for that and falls back to emulated prepared statements. But
presumably that doesn't work correctly.
------------------------------------------------------------------------
[2018-06-06 17:30:44] kbenton at activecampaign dot com
kbenton@localhost î° ~ î° php --version
PHP 7.2.6 (cli) (built: May 22 2018 16:22:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
kbenton@localhost î° ~ î° php testme.php
Exception caught: SQLSTATE[HY000]: General error: 2014 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.
Here!
kbenton@localhost î° ~ î° cat testme.php
<?php
try {
$pdo = new PDO('mysql:host=127.0.0.1', 'aql_app', '@ql_@pp');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$pdo->query('USE aql_db');
} catch ( Exception $e ) {
echo "Exception caught: {$e->getMessage()}\n";
}
echo "Here!\n";
kbenton@localhost î° ~ î°
------------------------------------------------------------------------
[2015-07-13 18:32:11] david at grudl dot com
Description:
------------
This code throws "SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other
unbuffered queries are active" on line 4.
The solution is to use exec() instead of query(), but I think that it is bug since there is no other
active query.
Test script:
---------------
$pdo = new PDO('mysql:host=127.0.0.1', '...', '...');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$pdo->query('USE nette_test');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70066&edit=1