1.20.x database.inc db_parse_url($url)

Parses the database URL.

By default, this calls the stock PHP parse_url() function. Some drivers that need special processing, such as SQLite, will override DatabaseConnection::parseDatabaseUrl(). See the database driver documentation for any special options.


string $url: The database URL. E.g., mysql://user:pass@localhost/database

Return value

mixed: An array with the URL's components, or FALSE on error.

Related topics


includes/database/database.inc, line 2851
Core systems for the database layer.


function db_parse_url($url) {
  // Get the scheme (driver type) from the URL.
  $matches = array();
  $preg_result = preg_match("/^(\w*):\/\/.*$/", $url, $matches);
  $driver = $preg_result ? $matches[1] : NULL;
  if (!$driver) {
    return FALSE;
  // Load the driver's database.inc file to get the DatabaseConnection class.
  Database::loadDriverFile($driver, array('database.inc'));
  $dbc_class = 'DatabaseConnection_' . $driver;
  if (!class_exists($dbc_class)) {
    return FALSE;

  // Parse the URL per the driver's rules.
  return $dbc_class::parseDatabaseUrl($url);