Make WordPress Core

Changeset 37548

Timestamp:
05/24/2016 05:23:06 AM (8 years ago)
Author:
pento
Message:

Database: Don't generate unnecessary warnings in wpdb::query().

In the event that the database has gone away for some reason, calls to mysqli_errno() and mysqli_error() (and their ext/mysql equivalents, of course), will generate PHP warnings, which are unsightly, and not how we do things in these parts.

Props mbijon, craig-ralston for the original patch.

Fixes #23085.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r37544 r37548  
    17201720        $this->check_current_query = true;
    17211721
    1722         // Keep track of the last query for debug..
     1722        // Keep track of the last query for debug.
    17231723        $this->last_query = $query;
    17241724
    17251725        $this->_do_query( $query );
    17261726
    1727         // MySQL server has gone away, try to reconnect
     1727        // MySQL server has gone away, try to reconnect
    17281728        $mysql_errno = 0;
    17291729        if ( ! empty( $this->dbh ) ) {
    17301730            if ( $this->use_mysqli ) {
    1731                 $mysql_errno = mysqli_errno( $this->dbh );
     1731                if ( $this->dbh instanceof mysqli ) {
     1732                    $mysql_errno = mysqli_errno( $this->dbh );
     1733                } else {
     1734                    // $dbh is defined, but isn't a real connection.
     1735                    // Something has gone horribly wrong, let's try a reconnect.
     1736                    $mysql_errno = 2006;
     1737                }
    17321738            } else {
    1733                 $mysql_errno = mysql_errno( $this->dbh );
     1739                if ( is_resource( $this->dbh ) ) {
     1740                    $mysql_errno = mysql_errno( $this->dbh );
     1741                } else {
     1742                    $mysql_errno = 2006;
     1743                }
    17341744            }
    17351745        }
     
    17441754        }
    17451755
    1746         // If there is an error then take note of it..
     1756        // If there is an error then take note of it.
    17471757        if ( $this->use_mysqli ) {
    1748             $this->last_error = mysqli_error( $this->dbh );
     1758            if ( $this->dbh instanceof mysqli ) {
     1759                $this->last_error = mysqli_error( $this->dbh );
     1760            } else {
     1761                $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
     1762            }
    17491763        } else {
    1750             $this->last_error = mysql_error( $this->dbh );
     1764            if ( is_resource( $this->dbh ) ) {
     1765                $this->last_error = mysql_error( $this->dbh );
     1766            } else {
     1767                $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
     1768            }
    17511769        }
    17521770
Note: See TracChangeset for help on using the changeset viewer.