public function Sqlmysql::creds

8.0.x Sqlmysql.php public Sqlmysql::creds($hide_password = TRUE)
7.x Sqlmysql.php public Sqlmysql::creds($hide_password = TRUE)
master Sqlmysql.php public Sqlmysql::creds($hide_password = TRUE)

Build a fragment connection parameters.

Parameters

bool $hide_password: If TRUE, DBMS should try to hide password from process list. On mysql, that means using --defaults-extra-file to supply the user+password.

Return value

string

Overrides SqlBase::creds

1 call to Sqlmysql::creds()
Sqlmysql::dumpCmd in lib/Drush/Sql/Sqlmysql.php

File

lib/Drush/Sql/Sqlmysql.php, line 11

Namespace

Drush\Sql

Class

Sqlmysql

Code

public function creds($hide_password = TRUE) {
  if ($hide_password) {
    // EMPTY password is not the same as NO password, and is valid.
    $contents = <<<EOT
#This file was written by Drush's Sqlmysql.inc.
[client]
user="{$this->db_spec['username']}"
password="{$this->db_spec['password']}"
EOT;

    $file = drush_save_data_to_temp_file($contents);
    $parameters['defaults-extra-file'] = $file;
  }
  else {
    // User is required. Drupal calls it 'username'. MySQL calls it 'user'.
    $parameters['user'] = $this->db_spec['username'];
    // EMPTY password is not the same as NO password, and is valid.
    if (isset($this->db_spec['password'])) {
      $parameters['password'] = $this->db_spec['password'];
    }
  }

  // Some drush commands (e.g. site-install) want to connect to the
  // server, but not the database.  Connect to the built-in database.
  $parameters['database'] = empty($this->db_spec['database']) ? 'information_schema' : $this->db_spec['database'];

  // Default to unix socket if configured.
  if (!empty($this->db_spec['unix_socket'])) {
    $parameters['socket'] = $this->db_spec['unix_socket'];
  }
  // EMPTY host is not the same as NO host, and is valid (see unix_socket).
  elseif (isset($this->db_spec['host'])) {
    $parameters['host'] = $this->db_spec['host'];
  }

  if (!empty($this->db_spec['port'])) {
    $parameters['port'] = $this->db_spec['port'];
  }

  return $this->params_to_options($parameters);
}