Bug #67004 [Ver->Csd]: Executing PDOStatement::fetch() more than once prevents releasing resultset

From: Date: Fri, 11 Dec 2020 11:56:17 +0000
Subject: Bug #67004 [Ver->Csd]: Executing PDOStatement::fetch() more than once prevents releasing resultset
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231012@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67004&edit=1 ID: 67004 Updated by: nikic@php.net Reported by: php_bugs at multiwebinc dot com Summary: Executing PDOStatement::fetch() more than once prevents releasing resultset -Status: Verified +Status: Closed Type: Bug Package: PDO MySQL Operating System: Ubuntu PHP Version: 5.5.10 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=ad8eb116d831035584e178bffb85d68c1ca3d7fa Log: Fixed bug #67004 Previous Comments: ------------------------------------------------------------------------ [2020-12-09 15:55:51] nikic@php.net Confirming this fails with libmysqlclient and works on mysqlnd. Adding an unset($stmt); also fixes the issue. ------------------------------------------------------------------------ [2014-04-07 07:44:29] 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. ------------------------------------------------------------------------ [2014-04-02 09:42:45] php_bugs at multiwebinc dot com Description: ------------ 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: http://stackoverflow.com/questions/22803938/what-is-causing-pdo-error-cannot-execute-queries-while-other-unbuffered-queries#22805988 Test script: --------------- The following works, however uncommenting the two lines that are commented produces the error above. <?php $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->prepare("SELECT ?"); $stmt->execute([0]); $result = $stmt->fetch(); // $stmt->execute([0]); // Uncomment these lines for error // $result = $stmt->fetch(); $stmt = $dbh->prepare("SELECT ?"); $stmt->execute([0]); $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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67004&edit=1

« previous php.bugs (#231012) next »