function Database::setActiveConnection

Same name in other branches
  1. 7.x includes/database/database.inc \Database::setActiveConnection()
  2. 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::setActiveConnection()
  3. 10 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::setActiveConnection()
  4. 11.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::setActiveConnection()

Sets the active connection to the specified key.

Return value

string|null The previous database connection key.

10 calls to Database::setActiveConnection()
DatabaseStorageTest::testConcurrent in core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageTest.php
Tests asynchronous table creation.
DbImportCommand::runScript in core/lib/Drupal/Core/Command/DbImportCommand.php
Run the database script.
LoggingTest::testEnableMultiConnectionLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests that we can log queries separately on different connections.
MigrateDrupalTestBase::loadFixture in core/modules/migrate_drupal/tests/src/Kernel/MigrateDrupalTestBase.php
Loads a database fixture into the source database connection.
MigrateUpgradeTestBase::loadFixture in core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeTestBase.php
Loads a database fixture into the source database connection.

... See full list

File

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

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static final function setActiveConnection($key = 'default') {
    if (!empty(self::$databaseInfo[$key])) {
        $old_key = self::$activeKey;
        self::$activeKey = $key;
        return $old_key;
    }
}

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