]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/commitdiff
Display SQL error during installation, if we get one.
authorBram Matthys <redacted>
Mon, 24 Apr 2023 13:17:39 +0000 (15:17 +0200)
committerBram Matthys <redacted>
Mon, 24 Apr 2023 13:17:39 +0000 (15:17 +0200)
api/installation.php
settings/install.php

index 15187a010a07eb9532aa39f2a2482ba42aa0a178..45b39192a34cbf831ef4742db2bef2edcbb52b36 100644 (file)
@@ -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"]));
 
 }
index 28886ddf3edc66a89070e3ba22603fba0388dedc..d215ed912dbd601332d7f2e5f30f3542206708ac 100644 (file)
@@ -285,6 +285,8 @@ $writable = (is_writable("../config/")) ? true: false;
        </div>
 </div>
 </form>
+
+<!-- Database overwrite prompt -->
 <div class="modal fade" id="db_overwrite_modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
@@ -307,6 +309,27 @@ $writable = (is_writable("../config/")) ? true: false;
        </div>
 </div>
 
+<!-- Database error dialog -->
+<div class="modal fade" id="db_error_modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalCenterTitle" aria-hidden="true">
+       <div class="modal-dialog modal-dialog-centered" role="document">
+               <div class="modal-content">
+               <div class="modal-header">
+                       <h5 class="modal-title" id="myModalLabel">Database server error</h5>
+                       <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                       <span aria-hidden="true">&times;</span>
+                       </button>
+               </div>
+               <div class="modal-body" id="db_error_text">
+                       Unable to connect to the database.
+               </div>
+               <div class="modal-footer">
+                               <button id="CloseButton" type="button" class="btn btn-primary" data-dismiss="modal">Ok</button>
+                       </form>
+               </div>
+               </div>
+       </div>
+</div>
+
 <script>
        let BASE_URL = '<?php echo BASE_URL; ?>';
        let chmod_help = document.getElementById('chmod_help');
@@ -401,6 +424,8 @@ $writable = (is_writable("../config/")) ? true: false;
                        else
                        {
                                sql_test_conn.innerHTML = "Failed!";
+                               $('#db_error_text').html(data.error ? data.error : 'An error occured while connecting to the DB server');
+                               $('#db_error_modal').modal();
                                setTimeout(function() {
                                        sql_test_conn.innerHTML = "Test connection";
                                        sql_test_conn.classList.remove('disabled');