diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-04 05:36:57 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2009-08-04 05:36:57 +0000 |
commit | 4e614ace820166d83b4767983404f79b2ba44949 (patch) | |
tree | 5ff3b3c40c308de0b1cc2c869cecfe6271662222 /includes | |
parent | b405e61329ba3d48602c9d24d641a8f4e099ef09 (diff) | |
download | brdo-4e614ace820166d83b4767983404f79b2ba44949.tar.gz brdo-4e614ace820166d83b4767983404f79b2ba44949.tar.bz2 |
#434350 by cpliakas and Crell: Add a method to explicitly close a database connection.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/database/database.inc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/database/database.inc b/includes/database/database.inc index 5063b4233..a093fab4b 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -1364,6 +1364,29 @@ abstract class Database { } /** + * Closes a connection to the server specified by the given key and target. + * + * @param $target + * The database target name. Defaults to NULL meaning that all target + * connections will be closed. + * @param $key + * The database connection key. Defaults to NULL which means the active key. + */ + public static function closeConnection($target = NULL, $key = NULL) { + // Gets the active conection by default. + if (!isset($key)) { + $key = self::$activeKey; + } + // To close the connection, we need to unset the static variable. + if (isset($target)) { + unset(self::$connections[$key][$target]); + } + else { + unset(self::$connections[$key]); + } + } + + /** * Instruct the system to temporarily ignore a given key/target. * * At times we need to temporarily disable slave queries. To do so, @@ -2072,6 +2095,20 @@ function db_driver() { } /** + * Closes the active database connection. + * + * @param $options + * An array of options to control which connection is closed. Only the + * target key has any meaning in this case. + */ +function db_close(array $options = array()) { + if (empty($options['target'])) { + $options['target'] = NULL; + } + Database::closeConnection($options['target']); +} + +/** * @} End of "defgroup database". */ |