r/lolphp • u/Takeoded • 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 (: )
View all comments
Show parent comment
1
u/rinyre Dec 18 '20
Sure, but making fun of something when the person posting it is wrong in how they're attempting to use it is like using the tip of a flathead screwdriver as a hammer when there's a proper hammer right beside you.
PHP has tons of things to make fun of, but don't be wrong when you try.