function drush_valid_db_credentials

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

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

1 call to drush_valid_db_credentials()


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


function drush_valid_db_credentials() {
  if (class_exists('PDO')) {
    $creds = drush_get_context('DRUSH_DB_CREDENTIALS');

    $type = ($creds['driver'] == 'mysqli') ? 'mysql' : $creds['driver'];

    if (!in_array($type, PDO::getAvailableDrivers())) {
      drush_log(dt('PDO support available, but the !type driver has not been installed. Assuming success.', array('!type' => $type)), 'bootstrap');
      return TRUE;

    $constr = sprintf("%s:dbname=%s;host=%s", $type, $creds['name'], $creds['host']);
    if (!empty($creds['port'])) {
      $constr .= sprintf(";port=%d", $creds['port']);

    try {
      $db = new PDO($constr, $creds['user'], $creds['pass']);
      $db = null;
      return TRUE;
    catch (PDOException $e) {
      // We do not use drush_set_error here , because it's up to the calling function
      // to determine whether or not this is an error or a warning.
      drush_log($e->getMessage(), 'warning');
      return FALSE;
  else {
    drush_log(dt('PDO support not available. Could not pre-validate database credentials. Assuming success'), 'bootstrap');
    return TRUE;