3

TL;DR I'm not asking how to make the error disappear, I don't want to know again that I can use fetchAll() and/or turn buffered queries on.


Yet another question about this error:

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.

there are countless posts about this, and they are great, but that's not my interest.

I don't just want the error to go away, I want to know if there is a way to identify which unbuffered queries are still active?

Since I'm only using MySQL, and my application will only run with MySQL, I could of course

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

but that's not the point.

The man page for pdo doesn't seem to have a method to do this, and the inTransaction() method doesn't apply since I'm not using transactions.

If it can help, all queries are prepared statements, just having the prepared sql would help me greatly pinpointing which query is not wholefully fetched.

var_dumping PDO object yields a not so useful result:

object(PDO)#31 (0) { } 

my wet dream would be to be able to use something like this:

var_dump($pdo->showActiveQueries());

which would return something like

array(2) { 
    [0]=> string(19) "SELECT foo FROM bar" 
    [1]=> string(21) "SELECT 2foo FROM 2bar" 
}
Community
  • 1
  • 1

1 Answers1

2

My understanding is that you could only do one unbuffered query at one time, so if that is the case, wouldn't it be the last query that was run before you get your error that would be the cause?

If you are using some sort of database abstraction, you could just grab the last successful query, and that would be the query causing the error.

Have you tried closing the cursor for the last query that was run before creating your new query? http://us.php.net/manual/en/pdostatement.closecursor.php

PDOStatement::closeCursor() frees up the connection to the server so that other SQL statements may be issued, but leaves the statement in a state that enables it to be executed again.

Tim Groeneveld
  • 8,739
  • 3
  • 44
  • 60