function _drush_sql_get_db_spec

6.x _drush_sql_get_db_spec()
3.x _drush_sql_get_db_spec()
4.x _drush_sql_get_db_spec()
5.x _drush_sql_get_db_spec()

Get a database specification for the active DB connection. Honors the 'database' and 'target command' line options.

Return value

An info array describing a database target.

7 calls to _drush_sql_get_db_spec()
drush_core_site_install_db_spec in commands/core/
drush_sql_build_dump_command in commands/sql/
drush_sql_conf in commands/sql/
Command callback. Displays the Drupal site's database connection string.
_drush_sql_get_credentials in commands/sql/
Build a fragment containing credentials and mysql-connection parameters.
_drush_sql_get_invalid_url_msg in commands/sql/

... See full list


commands/sql/, line 422
Drush sql commands


function _drush_sql_get_db_spec() {
  $database = drush_get_option('database', 'default');
  $target = drush_get_option('target', 'default');

  switch (drush_drupal_major_version()) {
    case 5:
    case 6:
      $url = $GLOBALS['db_url'];
      // TODO: array version not working?
      $url = is_array($url) ? $url[$database] : $url;
      return drush_convert_db_from_db_url($url);

      // We don't use DB API here `sql-sync` would have to messily addConnection.
      if (!isset($GLOBALS['databases']) || !array_key_exists($database, $GLOBALS['databases']) || !array_key_exists($target, $GLOBALS['databases'][$database])) {
        return NULL;
      return $GLOBALS['databases'][$database][$target];