function Database::addConnectionInfo

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

Adds database connection information for a given key/target.

This method allows the addition of new connection credentials at runtime. Under normal circumstances the preferred way to specify database credentials is via settings.php. However, this method allows them to be added at arbitrary times, such as during unit tests, when connecting to admin-defined third party databases, etc.

If the given key/target pair already exists, this method will be ignored.

Parameters

$key: The database key.

$target: The database target name.

$info: The database connection information, as it would be defined in settings.php. Note that the structure of this array will depend on the database driver it is connecting to.

11 calls to Database::addConnectionInfo()
ConnectionUnitTest::addConnection in modules/simpletest/tests/database_test.test
Adds a new database connection info to Database.
ConnectionUnitTest::setUp in modules/simpletest/tests/database_test.test
Sets up unit test environment.
DatabaseConnectionTestCase::testConnectionOptions in modules/simpletest/tests/database_test.test
Tests the connection options of the active database.
DatabaseConnectionTestCase::testConnectionRouting in modules/simpletest/tests/database_test.test
Test that connections return appropriate connection objects.
DatabaseConnectionTestCase::testConnectionRoutingOverride in modules/simpletest/tests/database_test.test
Test that connections return appropriate connection objects.

... See full list

File

includes/database/database.inc, line 1687

Class

Database
Primary front-controller for the database system.

Code

public static function addConnectionInfo($key, $target, $info) {
    if (empty(self::$databaseInfo[$key][$target])) {
        self::$databaseInfo[$key][$target] = $info;
    }
}

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