what does this error mean?
ERROR: Could not able to execute SELECT manufacturer,model FROM kvms INNER JOIN kvm_types ON kvms.kvm_type_id = kvm_types.kvm_type_id WHERE new = 1. 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.

Did you search for the error?

Please supply the relevant SQL Query to give others a chance at supplying a solution.

Yes, and the code that calls it. I did wonder if this was related to mysqli and a need to “use” the results of a query before running another, until I noticed the PDO bits of the error message.

The error means that you have not fetched all the data from one query before trying to execute another query. This either means that you didn’t fetch any/all the data from the first query before going on to run another query or that you are running a query inside of a loop that’s operating on data from the first query. For the first case, if you are executing a SELECT query, you should always fetch all the data from that query before going on to execute another query, which using the fetchAll() method will solve, or if the query is matching more data than you are using, modify the query to only match the data that you are interested in, and for the second case, you should not run queries inside of loops, use a single JOIN query instead.

The reason you receive this error is due to you use the “unbuffered” feature, when this mode is set you start processing data before the query to the MySQL server is completed. In this case, you need to process all the data, until the query is completed before you make another query.

Now, you use this feature when you want to reduce the memory use on PHP side when processing large dataset, or when you want to speed up processing on the PHP side. It can be quite effective in some use cases.

Though if you use this, you should NOT use fetchAll() etc., in that case you can just switch to the default buffered queries instead. Since it would be exactly the same.

Take a look in the manual for more information:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.