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\Database
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public static function convertDbUrlToConnectionInfo( $url , $root ) { $info = parse_url ( $url ); if (!isset( $info [ 'scheme' ], $info [ 'host' ], $info [ 'path' ])) { } $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 ; } |
Please login to continue.