ID: 38243 User updated by: shen dot shenstone at gmail dot com Reported By: shen dot shenstone at gmail dot com Status: Bogus Bug Type: PDO related Operating System: Windows PHP Version: 5.1.4 New Comment:
hum,,,but why it only raise error in two different classes, not in sequence query? thx...;) stone Previous Comments: ------------------------------------------------------------------------ [2006-07-28 18:26:24] [EMAIL PROTECTED] 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-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