final public static function Database::addConnectionInfo in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::addConnectionInfo()
- 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::addConnectionInfo()
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. Use \Drupal\Core\Database\Database::setActiveConnection to select the connection to use.
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.
See also
\Drupal\Core\Database\Database::setActiveConnection
43 calls to Database::addConnectionInfo()
- ConnectionTest::testConnectionOptions in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests the connection options of the active database.
- ConnectionTest::testConnectionRouting in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests that connections return appropriate connection objects.
- ConnectionTest::testConnectionRoutingOverride in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests that connections return appropriate connection objects.
- ConnectionTest::testPerTablePrefixOption in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests per-table prefix connection option.
- ConnectionTest::testPrefixArrayOption in core/
tests/ Drupal/ KernelTests/ Core/ Database/ ConnectionTest.php - Tests the prefix connection option in array form.
File
- core/
lib/ Drupal/ Core/ Database/ Database.php, line 274
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\DatabaseCode
public static final function addConnectionInfo($key, $target, array $info) {
if (empty(self::$databaseInfo[$key][$target])) {
self::$databaseInfo[$key][$target] = self::parseConnectionInfo($info);
}
}