function Database::parseConnectionInfo
Same name in other branches
- 7.x includes/database/database.inc \Database::parseConnectionInfo()
- 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()
- 10 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()
- 11.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()
Process the configuration file for database information.
Parameters
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.
1 call to Database::parseConnectionInfo()
- Database::addConnectionInfo in core/
lib/ Drupal/ Core/ Database/ Database.php - Adds database connection information for a given key/target.
File
-
core/
lib/ Drupal/ Core/ Database/ Database.php, line 229
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\DatabaseCode
public static final function parseConnectionInfo(array $info) {
// If there is no "driver" property, then we assume it's an array of
// possible connections for this target. Pick one at random. That allows
// us to have, for example, multiple replica servers.
if (empty($info['driver'])) {
$info = $info[mt_rand(0, count($info) - 1)];
}
// Parse the prefix information.
// @todo in Drupal 10, fail hard if $info['prefix'] is an array.
// @see https://www.drupal.org/project/drupal/issues/3124382
if (!isset($info['prefix'])) {
// Default to an empty prefix.
$info['prefix'] = '';
}
elseif (is_array($info['prefix'])) {
$prefix = $info['prefix']['default'] ?? '';
unset($info['prefix']['default']);
// If there are keys left besides the 'default' one, we are in a
// multi-prefix scenario (for per-table prefixing, or migrations).
// In that case, we put the non-default keys in a 'extra_prefix' key
// to avoid mixing up with the normal 'prefix', which is a string since
// Drupal 9.1.0.
if (count($info['prefix'])) {
$info['extra_prefix'] = $info['prefix'];
}
$info['prefix'] = $prefix;
}
// Backwards compatibility layer for Drupal 8 style database connection
// arrays. Those have the wrong 'namespace' key set, or not set at all
// for core supported database drivers.
if (empty($info['namespace']) || strpos($info['namespace'], 'Drupal\\Core\\Database\\Driver\\') === 0) {
switch (strtolower($info['driver'])) {
case 'mysql':
$info['namespace'] = 'Drupal\\mysql\\Driver\\Database\\mysql';
break;
case 'pgsql':
$info['namespace'] = 'Drupal\\pgsql\\Driver\\Database\\pgsql';
break;
case 'sqlite':
$info['namespace'] = 'Drupal\\sqlite\\Driver\\Database\\sqlite';
break;
}
}
// Backwards compatibility layer for Drupal 8 style database connection
// arrays. Those do not have the 'autoload' key set for core database
// drivers.
if (empty($info['autoload'])) {
switch (trim($info['namespace'], '\\')) {
case "Drupal\\mysql\\Driver\\Database\\mysql":
$info['autoload'] = "core/modules/mysql/src/Driver/Database/mysql/";
break;
case "Drupal\\pgsql\\Driver\\Database\\pgsql":
$info['autoload'] = "core/modules/pgsql/src/Driver/Database/pgsql/";
break;
case "Drupal\\sqlite\\Driver\\Database\\sqlite":
$info['autoload'] = "core/modules/sqlite/src/Driver/Database/sqlite/";
break;
}
}
return $info;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.