function Connection::destroy

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::destroy()

Destroys this Connection object.

PHP does not destruct an object if it is still referenced in other variables. In case of PDO database connection objects, PHP only closes the connection when the PDO object is destructed, so any references to this object may cause the number of maximum allowed connections to be exceeded.

Deprecated

in drupal:9.1.0 and is removed from drupal:10.0.0. Move custom database destruction logic to __destruct().

See also

https://www.drupal.org/node/3142866

1 call to Connection::destroy()
Connection::__destruct in core/lib/Drupal/Core/Database/Connection.php
Ensures that the client connection can be garbage collected.

File

core/lib/Drupal/Core/Database/Connection.php, line 329

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function destroy() {
    $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
    if ($backtrace[1]['class'] !== self::class && $backtrace[1]['function'] !== '__destruct') {
        @trigger_error(__METHOD__ . '() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Move custom database destruction logic to __destruct(). See https://www.drupal.org/node/3142866', E_USER_DEPRECATED);
        // Destroy all references to this connection by setting them to NULL.
        // The Statement class attribute only accepts a new value that presents a
        // proper callable, so we reset it to PDOStatement.
        // @todo remove this in Drupal 10 https://www.drupal.org/node/3177490
        if (!empty($this->statementClass)) {
            $this->connection
                ->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [
                'PDOStatement',
                [],
            ]);
        }
        $this->schema = NULL;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.