function drush_sitealias_get_db_spec

8.0.x drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '')
6.x drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '')
7.x drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '')
5.x drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '')
master drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '')

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.

The options 'database' and 'target' are used to specify which specific database should be fetched from the database record; they may appear in the alias definition, or may be taken from the command line options. The values 'default' and 'default' are used if these options are not specified in either location.

Note that in the context of sql-sync, the site alias record will be taken from one of the source or target aliases (e.g. `drush sql-sync @source @target`), which will be overlayed with any options that begin with 'source-' or 'target-', respectively. Therefore, the commandline options 'source-database' and 'source-target' (or 'target-database' and 'source-target') may also affect the operation of this function.

See also


2 calls to drush_sitealias_get_db_spec()
drush_archive_dump in commands/core/
Command callback. Generate site archive file.
drush_sql_sync in commands/sql/


includes/, line 846
The site alias API.


function drush_sitealias_get_db_spec(&$alias_record, $default_to_self = FALSE, $prefix = '') {
  $db_spec = NULL;
  $databases = sitealias_get_databases_from_record($alias_record);
  if (isset($databases) && !empty($databases)) {
    $database = drush_sitealias_get_option($alias_record, 'database', 'default', $prefix);
    $target = drush_sitealias_get_option($alias_record, 'target', 'default', $prefix);
    if (array_key_exists($database, $databases) && array_key_exists($target, $databases[$database])) {
      $db_spec = $databases[$database][$target];
  elseif ($default_to_self) {
    $db_spec = _drush_sql_get_db_spec();

  if (isset($db_spec)) {
    $remote_host = drush_sitealias_get_option($alias_record, 'remote-host', NULL, $prefix);
    if (!drush_is_local_host($remote_host)) {
      $db_spec['remote-host'] = $remote_host;
      $db_spec['port'] = drush_sitealias_get_option($alias_record, 'remote-port', (isset($db_spec['port']) ? $db_spec['port'] : NULL), $prefix);

  return $db_spec;