Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/wp-includes/class-wpdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/tests/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Loading