From 063085528cee56c1954d0c801ad3512538bc7987 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Sat, 24 Dec 2022 18:30:14 +0000 Subject: [PATCH 1/2] Add check of database credentials during setup before they are written to config.php --- setup.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.php b/setup.php index 85de0542..f7e2f2f2 100644 --- a/setup.php +++ b/setup.php @@ -782,6 +782,14 @@ if(isset($_POST['add_database'])){ $password = $_POST['password']; $config_base_url = $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']); + // Test database connection before writing it to config.php + try { + mysqli_connect($host, $username, $password, $database); + } + catch (Exception $e) { + exit("Database connection failed - please check and try again

$e"); + } + $new_config = array(); $new_config[] = " Date: Sat, 24 Dec 2022 18:35:44 +0000 Subject: [PATCH 2/2] Tidy try catch --- setup.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.php b/setup.php index f7e2f2f2..886d523f 100644 --- a/setup.php +++ b/setup.php @@ -785,8 +785,7 @@ if(isset($_POST['add_database'])){ // Test database connection before writing it to config.php try { mysqli_connect($host, $username, $password, $database); - } - catch (Exception $e) { + } catch (Exception $e) { exit("Database connection failed - please check and try again

$e"); }