function install_database_errors

Checks a database connection and returns any errors.

2 calls to install_database_errors()
install_settings_form_validate in drupal/core/includes/install.core.inc
Form validation handler for install_settings_form().
install_verify_database_settings in drupal/core/includes/install.core.inc
Verifies that settings.php specifies a valid database connection.

File

drupal/core/includes/install.core.inc, line 1132
API functions for installing Drupal.

Code

function install_database_errors($database, $settings_file) {
  global $databases;
  $errors = array();

  // Check database type.
  $database_types = drupal_get_database_types();
  $driver = $database['driver'];
  if (!isset($database_types[$driver])) {
    $errors['driver'] = st("In your %settings_file file you have configured @drupal to use a %driver server, however your PHP installation currently does not support this database type.", array(
      '%settings_file' => $settings_file,
      '@drupal' => drupal_install_profile_distribution_name(),
      '%driver' => $driver,
    ));
  }
  else {

    // Run driver specific validation
    $errors += $database_types[$driver]
      ->validateDatabaseSettings($database);

    // Run tasks associated with the database type. Any errors are caught in the
    // calling function.
    $databases['default']['default'] = $database;

    // Just changing the global doesn't get the new information processed.
    // We need to close any active connections and tell the Database class to
    // re-parse $databases.
    if (Database::isActiveConnection()) {
      Database::closeConnection();
    }
    Database::parseConnectionInfo();
    try {
      db_run_tasks($driver);
    } catch (TaskException $e) {

      // These are generic errors, so we do not have any specific key of the
      // database connection array to attach them to; therefore, we just put
      // them in the error array with standard numeric keys.
      $errors[$driver . '][0'] = $e
        ->getMessage();
    }
  }
  return $errors;
}