From b02688886a79879d90de2a708fbeb1fb2534acfe Mon Sep 17 00:00:00 2001 From: Baraka Kinywa Date: Sun, 22 Sep 2024 14:12:11 +0200 Subject: [PATCH] [FIX]setup_database.php: Check if the required MySQL extensions are loaded --- scripts/setup_database.php | 39 +++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/scripts/setup_database.php b/scripts/setup_database.php index 21ff8c9e1d..3c575e5caf 100755 --- a/scripts/setup_database.php +++ b/scripts/setup_database.php @@ -27,6 +27,39 @@ // NOTE: these sql commands could be db agnostic if we change the blobs to text +// Check if the required extensions for the configured DB driver are loaded +if ($db_driver == 'mysql') { + $required_extensions = ['mysqli', 'mysqlnd', 'pdo_mysql']; + $missing_extensions = []; + + foreach ($required_extensions as $extension) { + if (!extension_loaded($extension)) { + $missing_extensions[] = $extension; + } + } + + if (!empty($missing_extensions)) { + error_log('The following required MySQL extensions are missing: ' . implode(', ', $missing_extensions) . ". Please install them.\n"); + exit(1); + } +} elseif ($db_driver == 'pgsql') { + $required_extensions = ['pgsql', 'pdo_pgsql']; + $missing_extensions = []; + + foreach ($required_extensions as $extension) { + if (!extension_loaded($extension)) { + $missing_extensions[] = $extension; + } + } + + if (!empty($missing_extensions)) { + error_log('The following required PostgreSQL extensions are missing: ' . implode(', ', $missing_extensions) . ". Please install them.\n"); + exit(1); + } +} else { + error_log("Unsupported DB driver: {$db_driver}"); + exit(1); +} $connection_tries=0; $max_tries=10; @@ -43,7 +76,7 @@ printf("Attempting to connect to database ... ({$connection_tries}/{$max_tries})\n"); sleep(1); } - + if ($connection_tries >= $max_tries) { error_log('Unable to connect to database'); exit(1); @@ -85,7 +118,7 @@ } if (strcasecmp($user_config_type, 'DB')==0) { - + printf("Creating database table hm_user_settings ...\n"); if ($db_driver == 'mysql' || $db_driver == 'sqlite') { @@ -95,7 +128,7 @@ } else { die($bad_driver); } - + $conn->exec($stmt); }