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

Command icon 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:

Comments

Andrei Haurukovich created an issue. See original summary.

Andrei Haurukovich’s picture

Status: Active » Needs review
Andrei Haurukovich’s picture

Issue summary: View changes
Andrei Haurukovich’s picture

Issue summary: View changes
Andrei Haurukovich’s picture

Issue summary: View changes
Andrei Haurukovich’s picture

Issue summary: View changes
Igumnov_aleksey’s picture

I think this is a very important issue, it needs to be reviewed.

driverok’s picture

MR !2343 works for me - no more issues with batches on PHP 8.

poker10’s picture

Thanks 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!

avpaderno’s picture

Assigned: Andrei Haurukovich » Unassigned
poker10’s picture

Status: Needs review » Needs work

@Andrei Haurukovich can you verify if this is an issue on D10 as well (see #10)? Thanks!

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.