|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-07-23 04:23 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 19:00:01 2025 UTC |
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. )