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. Honors a --db-url option.

Return value

An info array describing a database target.

12 calls to _drush_sql_get_db_spec()
drush_core_pre_site_install in commands/core/
Perform setup tasks for installation.
drush_core_site_install_version in commands/core/drupal/
Install Drupal 7+
drush_db_select in includes/
A db_select() that works for any version of Drupal.
drush_sitealias_get_db_spec in includes/
Return the $db_spec record for the database associated with the provided alias record. which will be used to first add the database information to the alias records, invoking sql-conf to look them up if necessary.
drush_sql_conf in commands/sql/
Command callback. Displays the Drupal site's database connection string.

... See full list


commands/sql/, line 1066
Drush sql commands


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

  if ($url = drush_get_option('db-url')) {
    $url = is_array($url) ? $url[$database] : $url;
    $db_spec = drush_convert_db_from_db_url($url);
    $db_spec['db_prefix'] = drush_get_option('db-prefix');
    return $db_spec;
  elseif (($databases = drush_get_option('databases')) && (array_key_exists($database, $databases)) && (array_key_exists($target, $databases[$database]))) {
    return $databases[$database][$target];
  elseif (drush_bootstrap_max(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION)) {
    switch (drush_drupal_major_version()) {
      case 6:
        if ($url = isset($GLOBALS['db_url']) ? $GLOBALS['db_url'] : drush_get_option('db-url', NULL)) {
          $url = is_array($url) ? $url[$database] : $url;
          $db_spec = drush_convert_db_from_db_url($url);
          $db_spec['db_prefix'] = isset($GLOBALS['db_prefix']) ? $GLOBALS['db_prefix'] : drush_get_option('db-prefix', NULL);
          return $db_spec;
        return NULL;
        // 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];