Hey there,
I am currently trying to switch to PHP 8 and have a problem with DB queries.
I am testing locally with MAMP Pro
Apache/2.4.46
php8.0.0.fcgi
Mysql 5.7.32
In one of my plugins I store stats in a MySQL DB. After switching vom PHP 7.4 to 8.0 I get the following error:
PDOException thrown with message "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."
Stacktrace:
#9 PDOException in /MY-PATH/kirby/kirby-podcaster/kirby/src/Database/Database.php:444
#8 PDOStatement:fetchAll in /MY-PATH/kirby/kirby-podcaster/kirby/src/Database/Database.php:444
#7 Kirby\Database\Database:query in /MY-PATH/kirby/kirby-podcaster/utils/PodcasterStatsMysql.php:230
#6 mauricerenck\Podcaster\PodcasterStatsMySql:increaseFeedVisits in /MY-PATH/kirby/kirby-podcaster/utils/PodcasterStats.php:56
#5 mauricerenck\Podcaster\PodcasterStats:increaseFeedVisits in /MY-PATH/kirby/kirby-podcaster/index.php:100
#4 Kirby\Http\Route:mauricerenck\Podcaster\{closure} in [internal]:0
#3 Closure:call in /MY-PATH/kirby/kirby-podcaster/kirby/src/Http/Router.php:107
#2 Kirby\Http\Router:call in /MY-PATH/kirby/kirby-podcaster/kirby/src/Cms/App.php:336
#1 Kirby\Cms\App:call in /MY-PATH/kirby/kirby-podcaster/kirby/src/Cms/App.php:1039
#0 Kirby\Cms\App:render in /MY-PATH/kirby/kirby-podcaster/index.site.php:5
I am not doing anything fancy there:
$this->db->query('INSERT INTO podcaster_feeds […]');
Switching back to php 7.4 and everything is working again. Maybe setting the Bufferd Query as suggested may help, but as I don’t know in what kind of environments my plugin may be running, I want to avoid that. I am not sure if the problem is on my side or if I found a kirby bug. Maybe someone here may have an idea.