From 2fc3a1f8a7dd920ac6a533410a7cfebf0b823051 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 2 May 2026 00:38:38 +0000 Subject: [PATCH] Fix uncaught mysqli_sql_exception in PHP 8.1+ during install backup Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/e16b79db-af25-4a5f-828d-355ab71d8962 Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com> --- includes/database_mysqli.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/database_mysqli.php b/includes/database_mysqli.php index 6846bb21..4c161299 100644 --- a/includes/database_mysqli.php +++ b/includes/database_mysqli.php @@ -62,6 +62,11 @@ class OGPDatabaseMySQL extends OGPDatabase if ( $db_host === NULL ) return -1; + // PHP 8.1+ changed the default mysqli error reporting mode to throw exceptions. + // Disable that so all calling code can continue to rely on return-value error + // checking rather than exception handling. + mysqli_report(MYSQLI_REPORT_OFF); + // Use explicit port when provided; otherwise fall back to MySQL default (3306). $port = ($db_port !== NULL && $db_port !== '') ? (int)$db_port : NULL; $this->link = mysqli_connect( $db_host, $db_user, $db_pass, $db_name, $port ); @@ -81,7 +86,12 @@ class OGPDatabaseMySQL extends OGPDatabase if ( !$this->link ) return FALSE; ++$this->queries_; - $result = mysqli_query($this->link,$query); + try { + $result = mysqli_query($this->link,$query); + } catch ( \Throwable $e ) { + error_log("OGPDatabaseMySQL::listQuery exception: " . $e->getMessage()); + return FALSE; + } if ( mysqli_errno($this->link) > 0 ) print mysqli_error($this->link); @@ -1169,7 +1179,12 @@ class OGPDatabaseMySQL extends OGPDatabase $query = str_replace( "OGP_DB_PREFIX", $this->table_prefix, $query ); ++$this->queries_; - mysqli_query($this->link,$query); + try { + mysqli_query($this->link,$query); + } catch ( \Throwable $e ) { + error_log("OGPDatabaseMySQL::query exception: " . $e->getMessage()); + return FALSE; + } if( mysqli_errno($this->link) != 0 ) {