Database: address PHP 8.5 mysqli deprecation warning

This commit is contained in:
Aaron van Geffen 2025-04-18 19:26:50 +02:00
parent d6a319b886
commit 7faa59562d

View File

@ -28,17 +28,17 @@ class Database
*/ */
public function __construct($server, $user, $password, $name) public function __construct($server, $user, $password, $name)
{ {
$this->connection = @mysqli_connect($server, $user, $password, $name); try
// Give up if we have a connection error.
if (mysqli_connect_error())
{ {
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 '<h2>Database Connection Problems</h2><p>Our software could not connect to the database. We apologise for any inconvenience and ask you to check back later.</p>'; echo '<h2>Database Connection Problems</h2><p>Our software could not connect to the database. We apologise for any inconvenience and ask you to check back later.</p>';
exit; exit;
} }
$this->query('SET NAMES {string:utf8mb4}', ['utf8mb4' => 'utf8mb4']);
} }
public function getQueryCount() public function getQueryCount()