function drush_valid_db_credentials

8.0.x environment.inc drush_valid_db_credentials()
6.x environment.inc drush_valid_db_credentials()
7.x environment.inc drush_valid_db_credentials()
3.x environment.inc drush_valid_db_credentials()
4.x environment.inc drush_valid_db_credentials()
5.x environment.inc drush_valid_db_credentials()
master environment.inc drush_valid_db_credentials()

Tests the currently loaded database credentials to ensure a database connection can be made.

Parameters

bool $log_errors: (optional) If TRUE, log error conditions; otherwise be quiet.

Return value

bool TRUE if database credentials are valid.

1 call to drush_valid_db_credentials()

File

includes/environment.inc, line 381
Functions used by drush to query the environment and setting the current configuration.

Code

function drush_valid_db_credentials() {
  try {
    $sql = drush_sql_get_class();
    if (!$sqlVersion = drush_sql_get_version()) {
      drush_log(dt('While checking DB credentials, could not instantiate SQLVersion class.'), 'debug');
      return FALSE;
    }
    if (!$sqlVersion->valid_credentials($sql->db_spec())) {
      drush_log(dt('DB credentials are invalid.'), 'debug');
      return FALSE;
    }
    return $sql->query('SELECT 1;');
  }
  catch (Exception $e) {
    drush_log(dt('Checking DB credentials yielded error: @e', array('@e' => $e->getMessage())), 'debug');
    return FALSE;
  }
}