PHP Version: PHP 7.4.13
I have run into this issue where a fetchAll()
is being called on a prepared statement, with an UPDATE
query:
$stmt = $db->prepare( "UPDATE `table` SET value = value + ? WHERE id = ?" );
$success = $stmt->execute( $arguments );
$result = $stmt->fetchAll( PDO::FETCH_ASSOC ); // ← This causes the exception
While researching for causes for the MySQL error 2014 Cannot execute queries while other unbuffered queries are active
exception, it seems that this case is not covered on other questions asked here.
Why would $stmt->fetchAll()
on an UPDATE
query cause the following exception to happen?
PHP Fatal error: Uncaught PDOException: 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.
Specifically, I'd like to know what "other unbuffered queries are active" in this case is being referred to.
(I know it doesn't make sense, it is invalid and should not be done, but what I'm asking here is why would it result in that exception, specifically that "unbuffered" queries are active.)
n.b. – Setting MYSQL_ATTR_USE_BUFFERED_QUERY
to true
does not affect what I'm asking here.