Let the tests replace the database connection class.

This commit is contained in:
tim
2026-09-26 03:48:09 +02:00
parent 2c3a744e2e
commit a23f07cc48
+7 -2
View File
@@ -1,8 +1,12 @@
<?php
require_once(__DIR__ . '/config.lib.php');
global $db;
/*
* The class of the connection that open_db() makes. It is always mysqli
* on the site; the tests put a fake class in the global $db_class.
*/
function open_db($state) {
global $db;
global $db, $db_class;
if ($state == 'open') {
if (!$db) {
$hostname = config('DB_HOST', 'localhost');
@@ -11,7 +15,8 @@ function open_db($state) {
$db_name = config('DB_NAME');
// PHP 8.1+ throws exceptions by default; keep the old return-value checks working
mysqli_report(MYSQLI_REPORT_OFF);
$db = new mysqli($hostname, $view_user, $view_pass, $db_name);
$class = $db_class ?? 'mysqli';
$db = new $class($hostname, $view_user, $view_pass, $db_name);
if ($db->connect_error) {
$detail = 'connect error (' . $db->connect_errno . ') ' . $db->connect_error;
$db = NULL;