function drush_convert_db_from_db_url

8.0.x sitealias.inc drush_convert_db_from_db_url($db_url)
6.x sitealias.inc drush_convert_db_from_db_url($db_url)
7.x sitealias.inc drush_convert_db_from_db_url($db_url)
3.x sitealias.inc drush_convert_db_from_db_url($db_url)
4.x sitealias.inc drush_convert_db_from_db_url($db_url)
5.x sitealias.inc drush_convert_db_from_db_url($db_url)
master sitealias.inc drush_convert_db_from_db_url($db_url)

Convert from an old-style database URL to an array of database settings.

Parameters

db_url: A Drupal 6 db url string to convert, or an array with a 'default' element.

Return value

array An array of database values containing only the 'default' element of the db url. If the parse fails the array is empty.

4 calls to drush_convert_db_from_db_url()
drush_archive_restore in commands/core/archive.drush.inc
Command callback. Restore web site(s) from a site archive file.
drush_sitealias_convert_db_from_db_url in includes/sitealias.inc
Convert from an old-style database URL to an array of database settings
drush_sql_get_class in commands/sql/sql.drush.inc
Wrapper for drush_get_class; instantiates an driver-specific instance of SqlBase class.
Sql6::get_db_spec in lib/Drush/Sql/Sql6.php

File

includes/sitealias.inc, line 1613
The site alias API.

Code

function drush_convert_db_from_db_url($db_url) {
  $db_spec = array();

  if (is_array($db_url)) {
    $db_url_default = $db_url['default'];
  }
  else {
    $db_url_default = $db_url;
  }

  // If it's a sqlite database, pick the database path and we're done.
  if (strpos($db_url_default, 'sqlite://') === 0) {
    $db_spec = array(
      'driver' => 'sqlite',
      'database' => substr($db_url_default, strlen('sqlite://')),
    );
  }
  else {
    $url = parse_url($db_url_default);
    if ($url) {
      // Fill in defaults to prevent notices.
      $url += array(
        'scheme' => NULL,
        'user' => NULL,
        'pass' => NULL,
        'host' => NULL,
        'port' => NULL,
        'path' => NULL,
      );
      $url = (object) array_map('urldecode', $url);
      $db_spec = array(
        'driver' => $url->scheme == 'mysqli' ? 'mysql' : $url->scheme,
        'username' => $url->user,
        'password' => $url->pass,
        'host' => $url->host,
        'port' => $url->port,
        'database' => ltrim($url->path, '/'),
      );
    }
  }

  return $db_spec;
}