I'm using a PDO-MySQL in a class of my Accounting-Framework. The problem: if
I call my function query(), see below, multiple times, I get the error:


Array ( [0] => HY000 [1] => 2014 [2] => 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. ) 1


protected function query($query) {

      try {

            if (preg_match("@[EMAIL PROTECTED]", $query)) {

                  $sth = $this->link->prepare($query) or



                  // Get RowCount

                  $rc = 0;

                  while($count = $sth->fetch(PDO::FETCH_ASSOC)) $rc++;

                  $this->count[(string)$sth] = $rc;


                  return $sth;

            } else {


                  return true;


      } catch (Exception $e) {


            echo "DATABASE OPERATION FAILED: " . $e->getMessage();





The Solution described in the official manual is: 


$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);


My Connection function (which also includes the solution):


private function connect() {

      $this->link = new
PDO('mysql:host=localhost;dbname=micronax_mymicronax', "mymicronax",

      $this->link->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

      return true;



$link is defined as: protected $link = false;



But I still get the damn error-message. What's going wrong here?


Other possibilities, ex. Adding the MYSQL_ATTR_USE_BUFFERED_QUERY to "new
PDO()" or adding it to "prepare($query)" doesn't show affect.


Please help me,


Greetings from Germany and happy easter,



Fabian Golle

Salisweg 22e | 63454 Hanau

Tel.: +49 6181 26644

Mobil: +49 172 8183994

Web: http://www.micronax.de


(c) Micronax Systems 2007. All rights reserved


Reply via email to