|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-07-28 18:26 UTC] iliaa@php.net
[2006-07-29 20:05 UTC] shen dot shenstone at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
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(); ?>