1

I get an error when trying to perform a query that returns about 100,000 rows:

Fatal error: Uncaught exception 'PDOException' with message '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.'

The error seems to suggest that multiple queries are running at the same time, but upon checking the MySQL log this is not the case:

150226 15:10:28     3 Connect   root@localhost on Project
            3 Query SELECT * FROM Data WHERE posted > '2015-02-01 14:52:28' AND posted < '2015-02-19 18:36:56'
150226 15:11:00     3 Quit  

What are the causes of an error like this?

Turning on buffered queries is not an option because of the size of the result returned.

1
  • some php code might be helpful Commented Feb 26, 2015 at 15:19

1 Answer 1

1

The issue is that mysql only allows for one outstanding cursor at a given time. By using the fetch() method and not consuming all the pending data, you are leaving a cursor open.

The recommended approach is to consume all the data using the fetchAll() method. An alternative is to use the closeCursor() method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.