From dd0984f9e268a7b7e49659bfec5144b2c9ad7b74 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Wed, 24 Jul 2024 14:20:52 +0200 Subject: [PATCH] add check if database is empty --- install/includes/core/database_class.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/install/includes/core/database_class.php b/install/includes/core/database_class.php index 7334de9d1..22d94430d 100644 --- a/install/includes/core/database_class.php +++ b/install/includes/core/database_class.php @@ -50,22 +50,28 @@ class Database { try { $timeout = 5; /* five seconds for timeout */ $link = mysqli_init(); - + $link->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); - + $link->real_connect($data['db_hostname'], $data['db_username'], $data['db_password'], $data['db_name']); - + if ($link->connect_error) { - throw new Exception('Connection Error: ' . $link->connect_error); + throw new Exception(__("Connection Error: ") . $link->connect_error); } - + + $result = $link->query("SHOW TABLES"); + + if ($result->num_rows > 0) { + throw new Exception(__("Database is not empty.")); + } + $mysql_version = $link->server_info; - + $link->close(); - + return $mysql_version; } catch (Exception $e) { - return 'Error: ' . $e->getMessage(); + return __("Error: ") . $e->getMessage(); } } }