Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function Database::closeConnection

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

Parameters

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

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

7 calls to Database::closeConnection()
ConnectionUnitTest::testOpenClose in modules/simpletest/tests/database_test.test
Tests Database::closeConnection() without query.
ConnectionUnitTest::testOpenQueryClose in modules/simpletest/tests/database_test.test
Tests Database::closeConnection() with a query.
ConnectionUnitTest::testOpenQueryPrefetchClose in modules/simpletest/tests/database_test.test
Tests Database::closeConnection() with a query and custom prefetch method.
ConnectionUnitTest::testOpenSelectQueryClose in modules/simpletest/tests/database_test.test
Tests Database::closeConnection() with a select query.
Database::removeConnection in includes/database/database.inc
Remove a connection and its corresponding connection information.

... See full list

File

includes/database/database.inc, line 1818

Class

Database
Primary front-controller for the database system.

Code

public static function closeConnection($target = NULL, $key = NULL) {
 // Gets the active connection by default.
 if (!isset($key)) {
 $key = self ::$activeKey;
 }
 // To close a connection, it needs to be set to NULL and removed from the
 // static variable. In all cases, closeConnection() might be called for a
 // connection that was not opened yet, in which case the key is not defined
 // yet and we just ensure that the connection key is undefined.
 if (isset($target)) {
 if (isset(self ::$connections[$key][$target])) {
 self ::$connections[$key][$target]->destroy ();
 self ::$connections[$key][$target] = NULL;
 }
 unset(self ::$connections[$key][$target]);
 }
 else {
 if (isset(self ::$connections[$key])) {
 foreach (self ::$connections[$key] as $target => $connection) {
 self ::$connections[$key][$target]->destroy ();
 self ::$connections[$key][$target] = NULL;
 }
 }
 unset(self ::$connections[$key]);
 }
}

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