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>
This commit is contained in:
parent
0427f577c6
commit
2fc3a1f8a7
1 changed files with 17 additions and 2 deletions
|
|
@ -62,6 +62,11 @@ class OGPDatabaseMySQL extends OGPDatabase
|
||||||
if ( $db_host === NULL )
|
if ( $db_host === NULL )
|
||||||
return -1;
|
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).
|
// Use explicit port when provided; otherwise fall back to MySQL default (3306).
|
||||||
$port = ($db_port !== NULL && $db_port !== '') ? (int)$db_port : NULL;
|
$port = ($db_port !== NULL && $db_port !== '') ? (int)$db_port : NULL;
|
||||||
$this->link = mysqli_connect( $db_host, $db_user, $db_pass, $db_name, $port );
|
$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;
|
if ( !$this->link ) return FALSE;
|
||||||
|
|
||||||
++$this->queries_;
|
++$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 )
|
if ( mysqli_errno($this->link) > 0 )
|
||||||
print mysqli_error($this->link);
|
print mysqli_error($this->link);
|
||||||
|
|
@ -1169,7 +1179,12 @@ class OGPDatabaseMySQL extends OGPDatabase
|
||||||
$query = str_replace( "OGP_DB_PREFIX", $this->table_prefix, $query );
|
$query = str_replace( "OGP_DB_PREFIX", $this->table_prefix, $query );
|
||||||
|
|
||||||
++$this->queries_;
|
++$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 )
|
if( mysqli_errno($this->link) != 0 )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue