function _drush_sql_get_credentials

6.x sql.drush.inc _drush_sql_get_credentials($db_spec = NULL)
3.x sql.drush.inc _drush_sql_get_credentials($db_spec = NULL)
4.x sql.drush.inc _drush_sql_get_credentials($db_spec = NULL)
5.x sql.drush.inc _drush_sql_get_credentials($db_spec = NULL)

Build a fragment containing credentials and mysql-connection parameters.

Parameters

$db_spec:

Return value

string

5 calls to _drush_sql_get_credentials()
drush_core_pre_site_install in commands/core/site_install.drush.inc
drush_sql_build_dump_command in commands/sql/sql.drush.inc
drush_sql_cli in commands/sql/sql.drush.inc
_drush_sql_connect in commands/sql/sql.drush.inc
Command callback. Emits a connect string for mysql or pgsql.
_drush_sql_query in commands/sql/sql.drush.inc

File

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

Code

function _drush_sql_get_credentials($db_spec = NULL) {
  if (is_null($db_spec)) {
    $db_spec = _drush_sql_get_db_spec();
  }

  switch (_drush_sql_get_scheme($db_spec)) {
    case 'mysql':
      $cred = ' -h' . $db_spec['host'] . (empty($db_spec['port']) ? '' : ' -P' . $db_spec['port']) . ' -u' . $db_spec['username'] . (empty($db_spec['password']) ? '' : ' -p' . $db_spec['password']) . ' ' . $db_spec['database'];
      break;
    case 'pgsql':
      $cred = (isset($db_spec['database']) ? ' -d ' . (empty($db_spec['database']) ? 'template1' : $db_spec['database']) : '') . (empty($db_spec['host']) ? ' -h localhost ' : ' -h ' . $db_spec['host']) . (empty($db_spec['port']) ? ' -p 5432 ' : ' -p ' . $db_spec['port']);
      // Adding '-U' will cause Postgres to prompt for a password, so disable this for now.
      // Use "sudo -u postgres drush sql ..." to access the database without a password,
      // presuming that "postgres" is the database superuser and you have
      // "local all all ident sameuser" in your Postgres pg_hba.conf file.
      // See: http://drupal.org/node/438828
      $cred .= ' -U ' . $db_spec['username'] . ' ';
      break;
  }
  return escapeshellcmd($cred);
}