#33833 [Opn->Bgs]: fetch doesn't "finish" unbuffered query when all rows have been fetched

From: Date: Sat, 23 Jul 2005 02:23:57 +0000
Subject: #33833 [Opn->Bgs]: fetch doesn't "finish" unbuffered query when all rows have been fetched
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82350@lists.php.net to get a copy of this message
ID: 33833 Updated by: wez@php.net Reported By: james at safesearching dot com -Status: Open +Status: Bogus Bug Type: PDO related Operating System: * PHP Version: 5.1.0b3 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That's how it works. Previous Comments: ------------------------------------------------------------------------ [2005-07-23 03:44:39] james at safesearching dot com Description: ------------ When a query is expected to return one row, and therefor PDOStatement::fetch() is only called once, the query isn't "closed" or "finished" or whatever you like. The following calls fetch() twice, and only on the second call does the statment get released so that another statement can be prepared. $stmt = $db->prepare('SELECT CURDATE()'); while ($row = $stmt->fetch()) {} The following calls fetch once, and the statement is not released even though all the rows have been fetched. $stmt = $db->prepare('SELECT CURDATE()'); $row = $stmt->fetch(); Calling $stmt->closeCursor() all over the place seems a little kludgy... and I'm assuming $stmt->fetchAll(PDO_FETCH_BOUND) doesn't work. Reproduce code: --------------- $db = new PDO( 'mysql:dbname=test;host=localhost', 'teecor', 'k3y2t33c0r' ); $stmt = $db->prepare('SELECT CURDATE()'); $stmt->execute(); $row = $stmt->fetch(); print_r($row); $stmt = $db->prepare('SELECT CURDATE()'); print_r($db->errorInfo()); Expected result: ---------------- Array ( [0] => Array ( [CURDATE()] => 2005-07-22 [0] => 2005-07-22 ) ) Array ( [0] => 00000 ) Actual result: -------------- Array ( [CURDATE()] => 2005-07-22 [0] => 2005-07-22 ) Array ( [0] => HY000 [1] => 2014 [2] => 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. ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33833&edit=1

« previous php.bugs (#82350) next »