How to solve Generic error: 2014 Unable to execute queries while other unbuffered queries are active. using PDO connection

While I am executing the second stored procedure with the same join operator (using PDO) we get the following error.

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

SQLSTATE [HY000]: General error: 2014 Unable to execute queries while other unbuffered queries are active. Consider using PDOStatement :: fetchAll (). Also, if your code will only work with mysql, you can enable query buffering by setting PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY.

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

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 with this.

+3


source to share


1 answer


This is a slightly bad PDO feature and not well documented. The closeCursor method does not work when the operator has executed the stored procedure. You need to use the nextRowSet method. Here I am using



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

      

+2


source







All Articles