Add check of database credentials during setup before they are written to config.php

This commit is contained in:
Marcus Hill 2022-12-24 18:30:14 +00:00
parent 9587827792
commit 063085528c
1 changed files with 8 additions and 0 deletions

View File

@ -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("<b>Database connection failed - please check and try again</b> <br> <br> $e");
}
$new_config = array();
$new_config[] = "<?php\n\n";
$new_config[] = sprintf("\$dbhost = '%s';\n", addslashes($host));