|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33833 fetch doesn't "finish" unbuffered query when all rows have been fetched
Submitted: 2005-07-23 03:44 UTC Modified: 2005-07-23 04:23 UTC
From: james at safesearching dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.0b3 OS: *
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: james at safesearching dot com
New email:
PHP Version: OS:


 [2005-07-23 03:44 UTC] james at safesearching dot com
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(

$stmt = $db->prepare('SELECT CURDATE()');
$row = $stmt->fetch();


$stmt = $db->prepare('SELECT CURDATE()');


Expected result:
    [0] => Array
            [CURDATE()] => 2005-07-22
            [0] => 2005-07-22

    [0] => 00000

Actual result:
    [CURDATE()] => 2005-07-22
    [0] => 2005-07-22
    [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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-23 04:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

That's how it works.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 22:01:32 2024 UTC