function _drush_sql_get_db_spec

6.x sql.drush.inc _drush_sql_get_db_spec()
3.x sql.drush.inc _drush_sql_get_db_spec()
4.x sql.drush.inc _drush_sql_get_db_spec()
5.x sql.drush.inc _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/site_install.drush.inc
drush_sql_build_dump_command in commands/sql/sql.drush.inc
drush_sql_conf in commands/sql/sql.drush.inc
Command callback. Displays the Drupal site's database connection string.
_drush_sql_get_credentials in commands/sql/sql.drush.inc
Build a fragment containing credentials and mysql-connection parameters.
_drush_sql_get_invalid_url_msg in commands/sql/sql.drush.inc

... See full list

File

commands/sql/sql.drush.inc, line 422
Drush sql commands

Code

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);

    default:
      // 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];
  }
}