php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38243 execute two sequence query cause error when they only in two different class
Submitted: 2006-07-28 17:23 UTC Modified: 2006-07-29 20:05 UTC
From: shen dot shenstone at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.1.4 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: shen dot shenstone at gmail dot com
New email:
PHP Version: OS:

 

 [2006-07-28 17:23 UTC] shen dot shenstone at gmail dot com
Description:
------------
execute two sequence query cause error when they only in two different class.

the following code run WELL.
<?php
$db_host    = 'localhost';
$db_name    = 'jeon';
$db_port    = '3506';
$db_user    = 'test';
$db_pwd     = 'test';

$db = new PDO("mysql:host=$db_host;dbname=$db_name;port=$db_port", $db_user, $db_pwd, array(PDO::ATTR_PERSISTENT => true));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$r = $GLOBALS['db']->prepare("SELECT COUNT(*) FROM teacher WHERE teacherid=? AND password=?");
$r->execute(array('a', 'a'));

$r = $GLOBALS['db']->prepare("SELECT COUNT(*) FROM teacher WHERE teacherid=? AND password=?");
$r->execute(array('b', 'b'));
?>

But if i move the query code to different class, it does not working and raise a error.
"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."

only when i insert $r->closeCursor(); in the first class, they are working.

sorry for my bad english. ;)

Reproduce code:
---------------
<?php
$db_host    = 'localhost';$db_name    = 'jeon';$db_port    = '3506';$db_user    = 'test';$db_pwd     = 'test';
$db = new PDO("mysql:host=$db_host;dbname=$db_name;port=$db_port", $db_user, $db_pwd, array(PDO::ATTR_PERSISTENT => true));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
class Session{
    public function start_new() {
        $r = $GLOBALS['db']->prepare("SELECT COUNT(*) FROM teacher WHERE teacherid=? AND password=?");
        $r->execute(array('b', 'b'));
    }
}
class Test{
    function dotest() {
        $r = $GLOBALS['db']->prepare("SELECT COUNT(*) FROM teacher WHERE teacherid=? AND password=?");
        $r->execute(array('a', 'a'));
        //$r->closeCursor();
        $GLOBALS['session']->start_new();
    }
}
$session = new Session();$test = new Test();$test->dotest();
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-28 18:26 UTC] iliaa@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

Selects in pdo_mysql are normally buffered which means that 
before running a 2nd query you must either close the cursor or 
fetch all records. Alternatively you can use buffered queries, 
this is all expected behavior.
 [2006-07-29 20:05 UTC] shen dot shenstone at gmail dot com
hum,,,but why it only raise error in two different classes, not in sequence query?

thx...;)

stone
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 09:01:28 2025 UTC