Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::closeConnection()
- 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\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.
14 calls to Database::closeConnection()
- ConnectionFailureTest::testConnectionFailureLogging in core/
modules/ dblog/ tests/ src/ Kernel/ ConnectionFailureTest.php - Tests logging of connection failures.
- ConnectionTest::testConnectionClosing in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests the closing of a database connection.
- Database::removeConnection in core/
lib/ Drupal/ Core/ Database/ Database.php - Remove a connection and its corresponding connection information.
- InstallerIsolationLevelExistingSettingsTest::testInstaller in core/
modules/ mysql/ tests/ src/ Functional/ InstallerIsolationLevelExistingSettingsTest.php - Verifies that isolation_level is not set in the database settings.
- InstallerIsolationLevelNoDatabaseSettingsTest::testInstaller in core/
modules/ mysql/ tests/ src/ Functional/ InstallerIsolationLevelNoDatabaseSettingsTest.php - Verifies that the isolation_level was added to the database settings.
File
- core/
lib/ Drupal/ Core/ Database/ Database.php, line 484
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\DatabaseCode
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]);
}
// Force garbage collection to run. This ensures that client connection
// objects and results in the connection being closed are destroyed.
gc_collect_cycles();
}