#38243 [Opn->Bgs]: execute two sequence query cause error when they only in two different class
| From: | iliaa@php.net | Date: | Fri, 28 Jul 2006 18:26:24 +0000 |
| Subject: | #38243 [Opn->Bgs]: execute two sequence query cause error when they only in two different class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-100038@lists.php.net to get a copy of this message | ||
ID: 38243
Updated by: iliaa@php.net
Reported By: shen dot shenstone at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: PDO related
Operating System: Windows
PHP Version: 5.1.4
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
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.
Previous Comments:
------------------------------------------------------------------------
[2006-07-28 17:23:32] 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();
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=38243&edit=1