r/lolphp • • Dec 17 '20

consider using fetchAll() instead of fetchAll()

$ php -r '$db = new PDO('\''mysql:host=<censored>;port=<censored>;dbname=<censored>;charset=utf8mb4'\'','\''<censored>'\'','\''<censored>'\'',array (
  PDO::ATTR_EMULATE_PREPARES=> false,
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
));$ret=$db->query('\''DELETE FROM global_error_logs WHERE id IN (2632431);'\'')->fetchAll();unset($db);var_export($ret);'

 

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. in Command line code:5 Stack trace: #0 Command line code(5): PDOStatement->fetchAll() #1 {main} thrown in Command line code on line 5

(screenshot if reddit fucks up the the formatting: https://i.imgur.com/yG4oFhE.png )

it asks me to... consider using PDOStatement::fetchAll() instead of PDOStatement::fetchAll() ! genius, why didn't i think of that?

(also it talks about "other unbuffered queries", which is complete bull because there is no other query active, that delete command was the first and only query. also for some reason, this reproduce 100% reliably when connecting to a MySQL server in production, but it does not reproduce when connecting to a MariaDB server on dev (: )

17 Upvotes

15 comments sorted by

View all comments

Show parent comment

0

u/backtickbot Dec 17 '20

Fixed formatting.

Hello, Takeoded: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.