diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index aeb9679937935..997df462a13ff 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -2114,7 +2114,8 @@ public function parse_db_host( $host ) { * @return bool|void True if the connection is up. */ public function check_connection( $allow_bail = true ) { - if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) { + // Check if the connection is alive. + if ( ! empty( $this->dbh ) && mysqli_query( $this->dbh, 'DO 1' ) !== false ) { return true; } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 6c9bc91c85159..3e06afcc1bf2c 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -2455,4 +2455,15 @@ public function test_use_mysqli_property_access() { $this->assertTrue( $wpdb->use_mysqli ); } + + /** + * Verify "pinging" the database works cross-version PHP. + * + * @ticket 62061 + */ + public function test_check_connection_returns_true_when_there_is_a_connection() { + global $wpdb; + + $this->assertTrue( $wpdb->check_connection( false ) ); + } }