function drush_sql_su

6.x sql.drush.inc drush_sql_su($db_spec, $site_alias_record = NULL)
4.x sql.drush.inc drush_sql_su($db_spec)
5.x sql.drush.inc drush_sql_su($db_spec, $site_alias_record = NULL)

Build DB connection array with superuser credentials if provided.

The options 'db-su' and 'db-su-pw' will be retreived from the specified site alias record, if it exists and contains those items. If it does not, they will be fetched via drush_get_option.

Note that in the context of sql-sync, the site alias record will be taken from the target alias (e.g. `drush sql-sync @source @target`), which will be overlayed with any options that begin with 'target-'; therefore, the commandline options 'target-db-su' and 'target-db-su-pw' may also affect the operation of this function.

2 calls to drush_sql_su()
drush_sql_sync in commands/sql/sync.sql.inc
_drush_sql_create in commands/sql/sql.drush.inc
Generate CREATE DATABASE sql plus additonal preparations.

File

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

Code

function drush_sql_su($db_spec, $site_alias_record = NULL) {
  $create_db_target = $db_spec;
  $create_db_target['database'] = '';
  $db_superuser = drush_sitealias_get_option($site_alias_record, 'db-su');
  if (isset($db_superuser)) {
    $create_db_target['username'] = $db_superuser;
  }
  $db_su_pw = drush_sitealias_get_option($site_alias_record, 'db-su-pw');
  // If --db-su-pw is not provided and --db-su is, default to empty password.
  // This way db cli command will take password from .my.cnf or .pgpass.
  if (!empty($db_su_pw)) {
    $create_db_target['password'] = $db_su_pw;
  }
  elseif (isset($db_superuser)) {
    unset($create_db_target['password']);
  }
  return $create_db_target;
}