Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

mysql - how to resolve General error: 2014 Cannot execute queries while other unbuffered queries are active. using PDO connection

While i am executing second Stored procedure with same connection statement(Using PDO), getting the below error.

=================================================

SQLSTATE[HY000]: 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.

=======================================================

This is my code in drupal

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

$statement = $conn->prepare("CALL Odd_Get_Sport()");
$exec_result = $statement->execute();
while ($row = $statement->fetchObject()) {   
  print_r($row);
}


$statement ->closeCursor();

$statement1 = $conn->prepare("CALL Odd_Get_Sport()");
$exec_result1 = $statement1->execute();
while ($row1 = $statement1->fetchObject()) {   
   print_r($row1);
}

Help me on this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is a bit of a poor feature of PDO that's not well documented. The closeCursor method doesn't work when the statement has executed a stored procedure. You need to use the nextRowSet method. Here's what I use

            while($sth->nextRowSet())
        {
            $sth->fetchAll();
        }
        $sth->closeCursor();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...