8.5.x database.inc db_set_active($key = 'default')
8.0.x database.inc db_set_active($key = 'default')
8.1.x database.inc db_set_active($key = 'default')
8.2.x database.inc db_set_active($key = 'default')
8.3.x database.inc db_set_active($key = 'default')
8.4.x database.inc db_set_active($key = 'default')
8.6.x database.inc db_set_active($key = 'default')
4.6.x database.inc db_set_active($name = 'default')
4.7.x database.inc db_set_active($name = 'default')
5.x database.inc db_set_active($name = 'default')
6.x database.inc db_set_active($name = 'default')
7.x database.inc db_set_active($key = 'default')

Sets a new active database.

Parameters

$key: The key in the $databases array to set as the default database.

Return value

string|null The key of the formerly active database.

Deprecated

as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection().

Related topics

5 calls to db_set_active()
LoggingTest::testEnableMultiConnectionLogging in core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
Tests that we can log queries separately on different connections.
Tasks::connect in core/lib/Drupal/Core/Database/Install/Tasks.php
Check if we can connect to the database.
Tasks::connect in core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php
Check if we can connect to the database.
Tasks::connect in core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php
Check if we can connect to the database.
Tasks::connect in core/lib/Drupal/Core/Database/Driver/sqlite/Install/Tasks.php
Check if we can connect to the database.

File

core/includes/database.inc, line 337
Core systems for the database layer.

Code

function db_set_active($key = 'default') {
  return Database::setActiveConnection($key);
}