fix installation error on wrong credentials (#1175 and #1114)

This commit is contained in:
Thomas Citharel 2015-04-08 16:55:07 +02:00
parent 6f136f4df2
commit fdda9fd9a3

View file

@ -144,6 +144,10 @@ else if (isset($_POST['install'])) {
$sql_structure = file_get_contents('install/postgres.sql'); $sql_structure = file_get_contents('install/postgres.sql');
} }
// create database structure // create database structure
if (!$handle) {
$continue = false;
$errors[] = "Couldn't connect to your database server. Please check credentials.";
} else {
$query = $handle->exec($sql_structure); $query = $handle->exec($sql_structure);
$usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username)); $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username));
@ -151,9 +155,32 @@ else if (isset($_POST['install'])) {
$continue = false; $continue = false;
$errors[] = "An user already exists with this username in database."; $errors[] = "An user already exists with this username in database.";
} }
}
} catch (PDOException $e) { } catch (PDOException $e) {
$errors[] = $e->getMessage(); /* Error codes :
/ 7 : PostgreSQL issues
/ 1045 : Access denied to the user : user doesn't exists
/ 1044 : Access denied to the user : user doesn't have the rights to connect to this database
/ 2005 : Unknown database server
*/
switch ($e->getCode()) {
case 7:
$errors[] = "PostgreSQL has encountered an issue : " . $e->getMessage();
break;
case 1045:
$errors[] = "The password for this user is incorrect, or this user doesn't exist.";
break;
case 1044:
$errors[] = "The user isn't allowed to use this database.";
break;
case 2005:
$errors[] = "The server can't be reached.";
break;
default:
$errors[] = "A error happened while connecting to your database : " . $e->getMessage();
break;
}
$continue = false; $continue = false;
} }
} }