Make WordPress Core

Ticket #33926: 33926-db.patch

File 33926-db.patch, 964 bytes (added by wjywbs, 8 years ago)
  • src/wp-includes/wp-db.php

     
    15411541         */
    15421542        public function check_connection( $allow_bail = true ) {
    15431543                if ( $this->use_mysqli ) {
    1544                         if ( @mysqli_ping( $this->dbh ) ) {
     1544                        if ( !empty( $this->dbh ) && @mysqli_ping( $this->dbh ) ) {
    15451545                                return true;
    15461546                        }
    15471547                } else {
    1548                         if ( @mysql_ping( $this->dbh ) ) {
     1548                        if ( !empty( $this->dbh ) && @mysql_ping( $this->dbh ) ) {
    15491549                                return true;
    15501550                        }
    15511551                }
     
    16511651                // Keep track of the last query for debug..
    16521652                $this->last_query = $query;
    16531653
     1654                // Try to reconnect if the db handle is empty to avoid catchable fatal error.
     1655                if ( empty( $this->dbh ) && !$this->check_connection() ) {
     1656                        $this->insert_id = 0;
     1657                        return false;
     1658                }
     1659
    16541660                $this->_do_query( $query );
    16551661
    16561662                // MySQL server has gone away, try to reconnect