install_database_errors($database, $settings_file)Check a database connection and return any errors.
includes/install.core.inc, line 942
<?php
function install_database_errors($database, $settings_file) {
global $databases;
$errors = array();
// Verify the table prefix
if (!empty($database['db_prefix']) && is_string($database['db_prefix']) && !preg_match('/^[A-Za-z0-9_.]+$/', $database['db_prefix'])) {
$errors['db_prefix'] = st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $database['db_prefix']));
}
if (!empty($database['port']) && !is_numeric($database['port'])) {
$errors['db_port'] = st('Database port must be a number.');
}
// Check database type
$database_types = drupal_detect_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' => $database['driver']));
}
else {
// 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 tell tell the Database class to re-parse $databases.
Database::parseConnectionInfo();
try {
db_run_tasks($database['driver']);
}
catch (DatabaseTaskException $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[] = $e->getMessage();
}
}
return $errors;
}
?>