final public static function Database::addConnectionInfo

final public static Database::addConnectionInfo($key, $target, array $info)

Adds database connection information for a given key/target.

This method allows to add new connections 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

string $key: The database key.

string $target: The database target name.

array $info: The database connection information, as defined in settings.php. The structure of this array depends on the database driver it is connecting to.

File

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

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Database.php/function/Database::addConnectionInfo/8.1.x