Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Database.php

function Database::closeConnection

Closes a connection to the server specified by the given key and target.

Parameters

string $target: The database target name. Defaults to NULL meaning that all target connections will be closed.

string $key: The database connection key. Defaults to NULL which means the active key.

6 calls to Database::closeConnection()
Database::removeConnection in core/lib/Drupal/Core/Database/Database.php
Remove a connection and its corresponding connection information.
Tasks::checkBinaryOutput in core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
Check Binary Output.
Tasks::checkStandardConformingStrings in core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
Ensures standard_conforming_strings setting is 'on'.
Tasks::connect in core/modules/pgsql/src/Driver/Database/pgsql/Install/Tasks.php
Checks if we can connect to the database.
Tasks::connect in core/modules/sqlite/src/Driver/Database/sqlite/Install/Tasks.php
Checks if we can connect to the database.

... See full list

File

core/lib/Drupal/Core/Database/Database.php, line 441

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static function closeConnection($target = NULL, $key = NULL) {
    // Gets the active connection by default.
    if (!isset($key)) {
        $key = self::$activeKey;
    }
    if (isset($target) && isset(self::$connections[$key][$target])) {
        if (self::$connections[$key][$target] instanceof Connection) {
            self::$connections[$key][$target]->commitAll();
        }
        unset(self::$connections[$key][$target]);
    }
    elseif (isset(self::$connections[$key])) {
        foreach (self::$connections[$key] as $connection) {
            if ($connection instanceof Connection) {
                $connection->commitAll();
            }
        }
        unset(self::$connections[$key]);
    }
    // When last connection for $key is closed, we also stop any active
    // logging.
    if (empty(self::$connections[$key])) {
        unset(self::$logs[$key]);
    }
    // Force garbage collection to run. This ensures that client connection
    // objects and results in the connection being closed are destroyed.
    gc_collect_cycles();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal