Edit report at http://bugs.php.net/bug.php?id=44081&edit=1
ID: 44081 Comment by: andreas at schipplock dot de Reported by: abouzekry at gmail dot com Summary: Cannot execute queries while other unbuffered queries are active Status: Bogus Type: Bug Package: PDO related Operating System: Windows XP SP2 PHP Version: 5.2.9 Block user comment: N New Comment: running php 5.2.0-8+etch11 with debian and had the same problem. What "fixed" it for me was simply: $stmt = null; <-- after every fetchAll. I set up a test machine with vanilla php 5.3.3 and there setting it to null wasn't required; worked without modification. Previous Comments: ------------------------------------------------------------------------ [2009-09-09 20:54:23] sjo...@php.net Closing as requested. ------------------------------------------------------------------------ [2009-09-09 11:42:47] webmaster at rdwonline dot com I withdraw my bug report. I did not realize I was still using libmysql. Apparently I need the new MySQL native driver to get the most out of PDO_MYSQL. ------------------------------------------------------------------------ [2009-09-06 14:46:05] webmaster at rdwonline dot com I am using XAMPP (PHP 5.3.0 on Windows XP) and I am able to execute succeeding prepared statements with no problem as long as I call $PDOStatement->closeCursor() after I'm done with the previous one. The problem arises with MySQL stored procedures. PDO will execute and successfully retrieve records from the first stored procedure but all other statements afterwards WILL NOT EXECUTE, and I too get the error below: "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." I tried adding in the aforemention attribute to no avail. Here is a snippet from a script I used to test this: $PDOStatement = $PDO->prepare('SELECT * FROM MagicCards WHERE cardID = ?'); $PDOStatement->bindValue(1, 1600); $PDOStatement->execute(); $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); // works as expected $PDOStatement = $PDO->prepare('CALL uspGetMagicCardByKey(?)'); $PDOStatement->bindValue(1, 10); $PDOStatement->execute(); $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); //works as expected $PDOStatement = $PDO->prepare('SELECT * FROM MagicCards WHERE cardID = ?'); $PDOStatement->bindValue(1, 1600); $PDOStatement->execute(); //errors out right here with the HY000 error $PDOStatement->setFetchMode(\PDO::FETCH_ASSOC); $rows = $PDOStatement->fetchAll(); $PDOStatement->closeCursor(); $PDOStatement = NULL; print_r($rows); //doesn't get this far The workaround would be to drop in your SQL from your stored procedure directly as an argument to $PDO->prepare(). But if you are doing any other modifications before or after that main SELECT statement, this is not a feasible solution. This is a critical bug that needs to be fixed ASAP. ------------------------------------------------------------------------ [2009-07-23 08:30:58] sebastien dot barbieri at gmail dot com Same issue with PHP 5.2.10 (Linux/Mac/Windows) with a similar code: $this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES '.$this->options['charset'])); $this->dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); $this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $sth = $this->dbh->prepare($_stored_proc_1); $sth->bindValue('I_bind', $value, PDO::PARAM_STR); $sth->execute(); $object = $sth->fetchAll(PDO::FETCH_ASSOC); $sth->closeCursor(); $sth = $this->dbh->prepare($_stored_proc_2); $sth->bindValue('I_bind', $value, PDO::PARAM_STR); $sth->execute(); $object = $sth->fetchAll(PDO::FETCH_ASSOC); $sth->closeCursor(); However no problem at all if I install php 5.2.10 Zend Community Edition ... :-) ------------------------------------------------------------------------ [2009-06-10 21:49:52] stewart dot duncan at rocketmail dot com Confirmed, still broken in latest snapshot. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=44081 -- Edit this bug report at http://bugs.php.net/bug.php?id=44081&edit=1