X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/eddacbaa3591fc977610923885675239e5b1c4d1..67bff06aa6fd4d7d3a9aefc2919307326fa6d755:/api/installation.php diff --git a/api/installation.php b/api/installation.php index 15187a0..45b3919 100644 --- a/api/installation.php +++ b/api/installation.php @@ -13,19 +13,22 @@ if (!isset($_POST) || empty($_POST)) if ($_POST['method'] == "sql") { + try { $conn = mysqli_connect($_POST['host'], $_POST['user'], $_POST['password'], $_POST['database']); - - // check connection - if (mysqli_connect_errno()) - die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()])); - - $sql = "SHOW TABLES LIKE '".$conn->real_escape_string($_POST['table_prefix'])."%'"; // SQL query to check if table exists - $result = $conn->query($sql); - if ($result->num_rows > 0) - die(json_encode(["warn" => "Database already has data"])); - - // close connection - mysqli_close($conn); - die(json_encode(["success" => "SQL Connection successful"])); + } catch(Exception $e) + { + } + // check connection + if (mysqli_connect_errno()) + die(json_encode(["error" => "Failed to connect to MySQL: " . mysqli_connect_error()])); + + $sql = "SHOW TABLES LIKE '".$conn->real_escape_string($_POST['table_prefix'])."%'"; // SQL query to check if table exists + $result = $conn->query($sql); + if ($result->num_rows > 0) + die(json_encode(["warn" => "Database already has data"])); + + // close connection + mysqli_close($conn); + die(json_encode(["success" => "SQL Connection successful"])); }