Problem/Motivation
After execution a batch operation on PHP8 we use Database::closeConnection() that should avoid the MySql gone away error after a long batch operation. But Drupal throw an error
WD php: Error: User-supplied statement does not accept constructor [error]
arguments in PDO->prepare() (line 544 of ../docroot/includes/database/database.inc). Error: User-supplied statement does not accept constructor arguments in PDO->prepare() (line 544 of ../docroot/includes/database/database.inc).Steps to reproduce
Run some batch operation and then try to call Database::closeConnection() on PHP8. We have close issue with tests https://www.drupal.org/project/drupal/issues/3200708.
Seems that it issue reproduced before on php7.4 but now on php8 PDO library throws exception https://www.php.net/manual/en/pdo.error-handling.php.
Proposed resolution
I would suggest to apply fix that check in __destruct() method if we have DB connection that checks
public function __destruct() {
if (get_object_vars($this->connection) && ($this->needsCleanup)) {
$this->nextIdDelete();
}
}
Issue fork drupal-3283605
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3283605-error-on-php8
changes, plain diff MR !2343
Comments
Comment #3
Andrei Haurukovich commentedComment #4
Andrei Haurukovich commentedComment #5
Andrei Haurukovich commentedComment #6
Andrei Haurukovich commentedComment #7
Andrei Haurukovich commentedComment #8
Igumnov_aleksey commentedI think this is a very important issue, it needs to be reviewed.
Comment #9
driverok commentedMR !2343 works for me - no more issues with batches on PHP 8.
Comment #10
poker10 commentedThanks for working on this!
It would be great if we can check, if this is an issue also on D10. I briefly checked the D10 code and it seems like the
__destruct()function is practically the same as on D7 (https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/mysql...). Thanks!Comment #11
avpadernoComment #12
poker10 commented@Andrei Haurukovich can you verify if this is an issue on D10 as well (see #10)? Thanks!