On this page
public static function Database::convertDbUrlToConnectionInfo
public static Database::convertDbUrlToConnectionInfo($url, $root)
Converts a URL to a database connection info array.
Parameters
string $url: The URL.
string $root: The root directory of the Drupal installation.
Return value
array The database connection info.
Throws
\InvalidArgumentException Exception thrown when the provided URL does not meet the minimum requirements.
File
- core/lib/Drupal/Core/Database/Database.php, line 457
Class
- Database
- Primary front-controller for the database system.
Namespace
Drupal\Core\DatabaseCode
public static function convertDbUrlToConnectionInfo($url, $root) {
$info = parse_url($url);
if (!isset($info['scheme'], $info['host'], $info['path'])) {
throw new \InvalidArgumentException('Minimum requirement: driver://host/database');
}
$info += array(
'user' => '',
'pass' => '',
'fragment' => '',
);
// A SQLite database path with two leading slashes indicates a system path.
// Otherwise the path is relative to the Drupal root.
if ($info['path'][0] === '/') {
$info['path'] = substr($info['path'], 1);
}
if ($info['scheme'] === 'sqlite' && $info['path'][0] !== '/') {
$info['path'] = $root . '/' . $info['path'];
}
$database = array(
'driver' => $info['scheme'],
'username' => $info['user'],
'password' => $info['pass'],
'host' => $info['host'],
'database' => $info['path'],
);
if (isset($info['port'])) {
$database['port'] = $info['port'];
}
return $database;
}
© 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::convertDbUrlToConnectionInfo/8.1.x