From 3d87f8d0275d93bf67ea69a80353b19f6497d0b0 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Wed, 6 Aug 2025 16:20:41 +0200 Subject: [PATCH 1/8] fix: Function mysqli_ping() is deprecated since 8.4 This PR resolves "Deprecated: Function mysqli_ping() is deprecated since 8.4" warnings. https://www.php.net/manual/en/mysqli.ping.php https://php.watch/versions/8.2/mysqli-libmysql-no-longer-supported#mysqli-reconnect --- db.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/db.php b/db.php index 24e1d34..ac34b9b 100644 --- a/db.php +++ b/db.php @@ -1555,7 +1555,14 @@ public function ex_mysql_ping( $dbh ) { return @mysql_ping( $dbh ); } - return @mysqli_ping( $dbh ); + // Deprecated: Function mysqli_ping() is deprecated since 8.4 + if ( version_compare( PHP_VERSION, '8.4.0', '<' ) ) { + return @mysqli_ping( $dbh ); + } + + // Emulate ping with a simple query + $res = $this->ex_mysql_query( 'SELECT /* hyperbd::ex_mysql_ping */ 1', $dbh ); + return is_object( $res ) && $res->num_rows === 1; } public function ex_mysql_affected_rows( $dbh ) { From f9ce2d2395285893dd1097e9cdf4e45cc42f8f2c Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Wed, 6 Aug 2025 16:22:46 +0200 Subject: [PATCH 2/8] Use Yoda Condition checks, you must. --- db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db.php b/db.php index ac34b9b..e12170f 100644 --- a/db.php +++ b/db.php @@ -1562,7 +1562,7 @@ public function ex_mysql_ping( $dbh ) { // Emulate ping with a simple query $res = $this->ex_mysql_query( 'SELECT /* hyperbd::ex_mysql_ping */ 1', $dbh ); - return is_object( $res ) && $res->num_rows === 1; + return is_object( $res ) && 1 === $res->num_rows; } public function ex_mysql_affected_rows( $dbh ) { From 20a584adfc06e9da860fe0fd52da0a24c4449c7b Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Tue, 12 Aug 2025 10:15:06 +0200 Subject: [PATCH 3/8] Reconnect when the "SELECT 1" ping fails --- db.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/db.php b/db.php index e12170f..61d625c 100644 --- a/db.php +++ b/db.php @@ -1560,9 +1560,14 @@ public function ex_mysql_ping( $dbh ) { return @mysqli_ping( $dbh ); } - // Emulate ping with a simple query - $res = $this->ex_mysql_query( 'SELECT /* hyperbd::ex_mysql_ping */ 1', $dbh ); - return is_object( $res ) && 1 === $res->num_rows; + $res = $this->ex_mysql_query( 'SELECT /* hyperdb::ex_mysql_ping */ 1', $dbh ); + if ( is_object( $res ) && 1 === $res->num_rows ) { + // The "ping" query was enough, the database connection is still there. + return true; + } + + trigger_error( 'hyperdb::ex_mysql_ping needs to reconnect to the database', E_USER_WARNING ); + return $this->is_mysql_connection( $this->db_connect() ); } public function ex_mysql_affected_rows( $dbh ) { From ead28a01525665646b6d9a1c90956b4242cffb49 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Tue, 12 Aug 2025 10:17:20 +0200 Subject: [PATCH 4/8] Remove the trigger_error that we use internally in our fork of hyperdb. --- db.php | 1 - 1 file changed, 1 deletion(-) diff --git a/db.php b/db.php index 61d625c..962cd6e 100644 --- a/db.php +++ b/db.php @@ -1566,7 +1566,6 @@ public function ex_mysql_ping( $dbh ) { return true; } - trigger_error( 'hyperdb::ex_mysql_ping needs to reconnect to the database', E_USER_WARNING ); return $this->is_mysql_connection( $this->db_connect() ); } From e9e49289f05e3cb792e5d4e8ff35ba1ff4e88770 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Tue, 12 Aug 2025 12:54:20 +0200 Subject: [PATCH 5/8] The mysqli driver does not try to reconnect since PHP 8.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrija Vučinić --- db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db.php b/db.php index 962cd6e..47ae7a7 100644 --- a/db.php +++ b/db.php @@ -1556,7 +1556,7 @@ public function ex_mysql_ping( $dbh ) { } // Deprecated: Function mysqli_ping() is deprecated since 8.4 - if ( version_compare( PHP_VERSION, '8.4.0', '<' ) ) { + if ( version_compare( PHP_VERSION, '8.2.0', '<' ) ) { return @mysqli_ping( $dbh ); } From 46f74e01beb28c53c92a677474a5ffbc8041daa4 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Wed, 13 Aug 2025 13:26:19 +0200 Subject: [PATCH 6/8] Let the hyperdb logic reconnect us if the "ping" failed. --- db.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db.php b/db.php index 47ae7a7..b59e5ff 100644 --- a/db.php +++ b/db.php @@ -1566,7 +1566,8 @@ public function ex_mysql_ping( $dbh ) { return true; } - return $this->is_mysql_connection( $this->db_connect() ); + // Let the hyperdb logic reconnect us. + return false; } public function ex_mysql_affected_rows( $dbh ) { From 95e53043cb5b139c5cf19f20488b359d3d34c941 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Wed, 13 Aug 2025 13:29:25 +0200 Subject: [PATCH 7/8] Update the comment with more context on PHP 8.2 changes --- db.php | 1 + 1 file changed, 1 insertion(+) diff --git a/db.php b/db.php index b59e5ff..3c74c0a 100644 --- a/db.php +++ b/db.php @@ -1556,6 +1556,7 @@ public function ex_mysql_ping( $dbh ) { } // Deprecated: Function mysqli_ping() is deprecated since 8.4 + // The mysqli.reconnect php.ini setting had been ignored by the mysqlnd driver, and was removed as of PHP 8.2.0. if ( version_compare( PHP_VERSION, '8.2.0', '<' ) ) { return @mysqli_ping( $dbh ); } From 8a51769dec24eed55e59e3b8afd251311efd49b6 Mon Sep 17 00:00:00 2001 From: Maciej Brencz Date: Wed, 19 Nov 2025 11:17:35 +0000 Subject: [PATCH 8/8] Handle MySQL server gone error by disconnecting Disconnect from database on server gone error. --- db.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db.php b/db.php index 07f5566..21bff80 100644 --- a/db.php +++ b/db.php @@ -1402,8 +1402,8 @@ public function should_mysql_ping() { // MySQL server has gone away if ( isset( $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] ) && HYPERDB_SERVER_GONE_ERROR == $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] ) { - unset( $this->dbhname_heartbeats[ $this->dbhname ]['last_errno'] ); - return true; + $this->disconnect( $this->dbhname ); + return false; } // More than 0.1 seconds of inactivity on that dbhname