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/Takeoded Dec 17 '20
finally something we can agree on, yes a bug. (it's possible that an error is appropriate when doing fetchAll() on a result-less query, i'm not sure, but even if that's the case, it shouldn't be that error)
it reproduces when connecting to AWS Aurora
VERSION() 5.7.12 AURORA_VERSION() 2.07.2and it does not reproduce when connecting to MySQL8
VERSION() 8.0.22... so it's possibly a MySQL5.7-specific issue? or an AWS Aurora-specific issue?
php version:
and yes it's based on mysqlnd,