|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67004 Executing PDOStatement::fetch() more than once prevents releasing resultset
Submitted: 2014-04-02 09:42 UTC Modified: 2020-12-09 15:55 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: php_bugs at multiwebinc dot com Assigned:
Status: Closed Package: PDO MySQL
PHP Version: 5.5.10 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php_bugs at multiwebinc dot com
New email:
PHP Version: OS:


 [2014-04-02 09:42 UTC] php_bugs at multiwebinc dot com
When executing PDOStatement::fetch() more than once on the same statement, the resultset is not released and subsequent calls to PDO::prepare() produce the error:

"Fatal error: Uncaught exception 'PDOException' with message '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.'"

My PHP is PHP 5.5.3-1ubuntu2.2 and MySQL 5.5.35 on Ubuntu 13.10, however this bug doesn't appear to affect all versions since someone else tested it using the same code and was unable to produce the error unless PDO::MYSQL_ATTR_USE_BUFFERED_QUERY was set to false. See this thread I started here:

Test script:
The following works, however uncommenting the two lines that are commented produces the error above.

$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$stmt = $dbh->prepare("SELECT ?");
$result = $stmt->fetch();

// $stmt->execute([0]); // Uncomment these lines for error
// $result = $stmt->fetch();

$stmt = $dbh->prepare("SELECT ?");
$result = $stmt->fetch();

Expected result:
I would expect that executing a prepared statement more than once would not have any effect on whether the unbuffered queries are released or not. It should perform just like the first time.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-07 07:44 UTC] php_bugs at multiwebinc dot com
Doing more tests, this error only occurs when using the libmysqlclient driver. The error does not appear when using mysqlnd, so there must be a bug either with libmysqlclient or PDO when those two are used together.

Note also, I am unable to reproduce the error using mysqli.
 [2020-12-09 15:55 UTC]
-Status: Open +Status: Verified
 [2020-12-09 15:55 UTC]
Confirming this fails with libmysqlclient and works on mysqlnd.

Adding an unset($stmt); also fixes the issue.
 [2020-12-11 11:56 UTC]
Automatic comment on behalf of
Log: Fixed bug #67004
 [2020-12-11 11:56 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 02:01:29 2024 UTC