|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70066 Unexpected "Cannot execute queries while other unbuffered queries"
Submitted: 2015-07-13 18:32 UTC Modified: 2020-12-09 16:06 UTC
Avg. Score:3.8 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: david at grudl dot com Assigned:
Status: Closed Package: PDO MySQL
PHP Version: 5.6.11 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
33 - 14 = ?
Subscribe to this entry?

 [2015-07-13 18:32 UTC] david at grudl dot com
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=', '...', '...');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
$pdo->query('USE nette_test');


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-06 17:30 UTC] 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.
 kbenton@localhost  ~  cat testme.php

try {
    $pdo = new PDO('mysql:host=', 'aql_app', '@ql_@pp');
    $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  ~ 
 [2020-12-09 16:06 UTC]
-Status: Open +Status: Verified
 [2020-12-09 16:06 UTC]
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.
 [2020-12-09 16:25 UTC]
Automatic comment on behalf of
Log: Fixed bug #70066
 [2020-12-09 16:25 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 07:03:37 2021 UTC