From 7faa59562d0c2a56983129175be521c45f378ef9 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Fri, 18 Apr 2025 19:26:50 +0200 Subject: [PATCH] Database: address PHP 8.5 mysqli deprecation warning --- models/Database.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/models/Database.php b/models/Database.php index 66363b3..c8e2e02 100644 --- a/models/Database.php +++ b/models/Database.php @@ -28,17 +28,17 @@ class Database */ public function __construct($server, $user, $password, $name) { - $this->connection = @mysqli_connect($server, $user, $password, $name); - - // Give up if we have a connection error. - if (mysqli_connect_error()) + try { - header('HTTP/1.1 503 Service Temporarily Unavailable'); + $this->connection = new mysqli($server, $user, $password, $name); + $this->connection->set_charset('utf8mb4'); + } + catch (mysqli_sql_exception $e) + { + http_response_code(503); echo '

Database Connection Problems

Our software could not connect to the database. We apologise for any inconvenience and ask you to check back later.

'; exit; } - - $this->query('SET NAMES {string:utf8mb4}', ['utf8mb4' => 'utf8mb4']); } public function getQueryCount()