php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: james at safesearching dot com
New email:
PHP Version: OS:

 

 [2005-07-23 03:44 UTC] 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.
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-23 04:23 UTC] wez@php.net
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.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 00:01:22 2020 UTC