PDO MySQL Error: cannot execute queries while other unbuffered queries is active

Source: Internet
Author: User
Tags prepare stmt

Operating environment: PHP 5.5.30-x64,mysql 5.6.27

Error code: Cannot execute queries while other unbuffered queries is active.  Consider using Pdostatement::fetchall (). Alternatively, if your code is a ever going to run against MySQL, you may enable query buffering by setting the Pdo::my Sql_attr_use_buffered_query attribute.

on-line explanations :

The test was found because several SQL statements were executed in the previous execute (that is, a semicolon-delimited select/insert/update that performed multiple times consecutively). That is, the query is queried again without ending the previous one, so it will go wrong, so release the previous query.

the code on the manual :

<?php if ($db-getattribute (PDO:: attr_driver_name) = =  ' mysql ') {     $stmt  = $db,  prepare (' SELECT * from foo ',        Array (PDO:: Mysql_attr_use_buffered_query  =  true);} else {    

If This attribute are set to TRUE on a pdostatement, the MySQL driver would use the buffered versions of the MySQL API. If you ' re writing portable code, you should use Pdostatement::fetchall () instead.

Tested many times or had problems .....

The code runs multiple query,optimize table,delete operations. This error was found to be caused by optimize table. The code runs correctly after the comment is dropped.

Use optimize TABLE:

<?phpclass database extends pdo{//table prefix public $prefix = ';        Some Code//optimization table function optimize ($table) {$stmt  =  $this, prepare (' Optimize table '. $this->prefix. $table .‘ ", Array (PDO:: Mysql_attr_use_buffered_query  =  true); return $stmt-Execute ();}   

La La ...

PDO MySQL Error: cannot execute queries while other unbuffered queries is active

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.