[PDO] Cannot execute queries while other unbuffered queries are active

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

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("@^select@is", $query)) {

                  $sth = $this->link->prepare($query) or
die(print_r($this->link->errorInfo()));

                  $sth->execute();

                        

                  // Get RowCount

                  $rc = 0;

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

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

                  $sth->execute();

                  return $sth;

            } else {

                  $this->link->query($query);

                  return true;

            }

      } catch (Exception $e) {

            $dbh->rollBack();

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

            exit;

      }

}

 

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",
"l{7kD01eG-B[");

      $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

Email: f.golle@xxxxxxxxxxxxxx

(c) Micronax Systems 2007. All rights reserved

 


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux