Bug #67004 [NEW]: Executing PDOStatement::fetch() more than once prevents releasing resultset
| From: | php_bugs at multiwebinc dot com | Date: | Wed, 02 Apr 2014 09:42:46 +0000 |
| Subject: | Bug #67004 [NEW]: Executing PDOStatement::fetch() more than once prevents releasing resultset | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185028@lists.php.net to get a copy of this message | ||
From: php_bugs at multiwebinc dot com
Operating system: Ubuntu
PHP version: 5.5.10
Package: PDO MySQL
Bug Type: Bug
Bug description:Executing PDOStatement::fetch() more than once prevents releasing resultset
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 bug report at https://bugs.php.net/bug.php?id=67004&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67004&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67004&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67004&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67004&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67004&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67004&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67004&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67004&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67004&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67004&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67004&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67004&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67004&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67004&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67004&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67004&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67004&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67004&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67004&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67004&r=mysqlcfg