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::renameConnection

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()
  2. 10 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()
  3. 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()
  4. 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::renameConnection()

Rename a connection and its corresponding connection information.

Parameters

$old_key: The old connection key.

$new_key: The new connection key.

Return value

TRUE in case of success, FALSE otherwise.

4 calls to Database::renameConnection()
DrupalUnitTestCase::setUp in modules/simpletest/drupal_web_test_case.php
Sets up unit test environment.
DrupalUnitTestCase::tearDown in modules/simpletest/drupal_web_test_case.php
DrupalWebTestCase::changeDatabasePrefix in modules/simpletest/drupal_web_test_case.php
Changes the database connection to the prefixed one.
DrupalWebTestCase::tearDown in modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.

File

includes/database/database.inc, line 1719

Class

Database
Primary front-controller for the database system.

Code

final public static function renameConnection($old_key, $new_key) {
 if (empty(self ::$databaseInfo)) {
 self ::parseConnectionInfo ();
 }
 if (!empty(self ::$databaseInfo[$old_key]) && empty(self ::$databaseInfo[$new_key])) {
 // Migrate the database connection information.
 self ::$databaseInfo[$new_key] = self ::$databaseInfo[$old_key];
 unset(self ::$databaseInfo[$old_key]);
 // Migrate over the DatabaseConnection object if it exists.
 if (isset(self ::$connections[$old_key])) {
 self ::$connections[$new_key] = self ::$connections[$old_key];
 unset(self ::$connections[$old_key]);
 }
 return TRUE;
 }
 else {
 return FALSE;
 }
}

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