summaryrefslogtreecommitdiffstats
path: root/inc/database.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2025-05-20 14:42:12 +0200
committerSimon Rettberg2025-05-20 14:42:12 +0200
commitd71bbd7ad6180387c65e2f668945f6bec81d856f (patch)
treebaa31d50b332360151fb7942b1e00997152dc572 /inc/database.inc.php
parent[vmstore] "Satellite server" instead of "<self>" in benchmark server select (diff)
downloadslx-admin-d71bbd7ad6180387c65e2f668945f6bec81d856f.tar.gz
slx-admin-d71bbd7ad6180387c65e2f668945f6bec81d856f.tar.xz
slx-admin-d71bbd7ad6180387c65e2f668945f6bec81d856f.zip
[inc/Database] Check if ErrorHandler is available before calling it
Diffstat (limited to 'inc/database.inc.php')
-rw-r--r--inc/database.inc.php25
1 files changed, 23 insertions, 2 deletions
diff --git a/inc/database.inc.php b/inc/database.inc.php
index f928b7f5..278fd8f0 100644
--- a/inc/database.inc.php
+++ b/inc/database.inc.php
@@ -2,6 +2,8 @@
declare(strict_types=1);
+use JetBrains\PhpStorm\NoReturn;
+
/**
* Handle communication with the database
* This is a very thin layer between you and PDO.
@@ -221,7 +223,7 @@ class Database
self::$lastError = implode("\n", $stmt->errorInfo());
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
return false;
- ErrorHandler::traceError("Database Error: \n" . self::$lastError);
+ self::traceError("Database Error: \n" . self::$lastError);
}
if (CONFIG_DEBUG) {
$duration = microtime(true) - $start;
@@ -239,7 +241,26 @@ class Database
self::$lastError = '(' . $e->getCode() . ') ' . $e->getMessage();
if ($ignoreError === true || ($ignoreError === null && self::$returnErrors))
return false;
- ErrorHandler::traceError("Database Error: \n" . self::$lastError);
+ self::traceError("Database Error: \n" . self::$lastError);
+ }
+ }
+
+ /**
+ * Wrapper around ErrorHandler::traceError as the autoloader might not
+ * be available at all times.
+ */
+ #[NoReturn]
+ private static function traceError(string $message): void
+ {
+ if (class_exists('ErrorHandler')) {
+ ErrorHandler::traceError($message);
+ } else {
+ error_log($message);
+ foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $i => $e) {
+ error_log("#$i {$e['file']}:{$e['line']} ({$e['function']})");
+ }
+ http_response_code(500);
+ exit(1);
}
}