public static function 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()
ConnectionTest::testConnectionOptions in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php
Tests the connection options of the active database.
ConnectionTest::testConnectionRouting in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php
Tests that connections return appropriate connection objects.
ConnectionTest::testConnectionRoutingOverride in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionTest.php
Tests that connections return appropriate connection objects.
ConnectionUnitTest::addConnection in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php
Adds a new database connection info to Database.
ConnectionUnitTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Database/ConnectionUnitTest.php
Sets up unit test environment.

... See full list

File

drupal/core/lib/Drupal/Core/Database/Database.php, line 276
Definition of Drupal\Core\Database\Database

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

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