public function SqlBase::su

8.0.x SqlBase.php public SqlBase::su()
7.x SqlBase.php public SqlBase::su()
master SqlBase.php public SqlBase::su()

Adjust DB connection 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.

Return value

null

1 call to SqlBase::su()
SqlBase::createdb in lib/Drush/Sql/SqlBase.php
Create a new database.

File

lib/Drush/Sql/SqlBase.php, line 373

Namespace

Drush\Sql

Class

SqlBase

Code

public function su() {
  $create_db_target = $this->db_spec;

  $create_db_target['database'] = '';
  $db_superuser = drush_get_option('db-su');
  if (isset($db_superuser)) {
    $create_db_target['username'] = $db_superuser;
  }
  $db_su_pw = drush_get_option('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']);
  }
  $this->db_spec = $create_db_target;
}