From: Thomas Citharel Date: Wed, 8 Apr 2015 14:55:07 +0000 (+0200) Subject: fix installation error on wrong credentials (#1175 and #1114) X-Git-Tag: 1.9.1beta1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=fdda9fd9a356b38aad39a4f3703085ce8afc161b;p=github%2Fwallabag%2Fwallabag.git fix installation error on wrong credentials (#1175 and #1114) --- diff --git a/install/index.php b/install/index.php index fc16af0c..77e50864 100755 --- a/install/index.php +++ b/install/index.php @@ -144,16 +144,43 @@ else if (isset($_POST['install'])) { $sql_structure = file_get_contents('install/postgres.sql'); } // create database structure - $query = $handle->exec($sql_structure); - - $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username)); - if (!empty($usertest)) { - $continue = false; - $errors[] = "An user already exists with this username in database."; - } + if (!$handle) { + $continue = false; + $errors[] = "Couldn't connect to your database server. Please check credentials."; + } else { + $query = $handle->exec($sql_structure); + + $usertest = executeQuery($handle,"SELECT * from users WHERE username = ?", array($username)); + if (!empty($usertest)) { + $continue = false; + $errors[] = "An user already exists with this username in database."; + } + } } 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; } }