diff --git a/db.php b/db.php index 6643331..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 @@ -1556,7 +1556,20 @@ public function ex_mysql_ping( $dbh ) { return @mysql_ping( $dbh ); } - return @mysqli_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 ); + } + + $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; + } + + // Let the hyperdb logic reconnect us. + return false; } public function ex_mysql_affected_rows( $dbh ) {