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.



git-svn-id: https://develop.svn.wordpress.org/trunk@37548 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2016-05-24 05:23:06 +00:00
parent ae03e5cbb4
commit 01356e100e

View File

@ -1719,18 +1719,28 @@ class wpdb {
$this->check_current_query = true;
// Keep track of the last query for debug..
// Keep track of the last query for debug.
$this->last_query = $query;
$this->_do_query( $query );
// MySQL server has gone away, try to reconnect
// MySQL server has gone away, try to reconnect.
$mysql_errno = 0;
if ( ! empty( $this->dbh ) ) {
if ( $this->use_mysqli ) {
if ( $this->dbh instanceof mysqli ) {
$mysql_errno = mysqli_errno( $this->dbh );
} else {
// $dbh is defined, but isn't a real connection.
// Something has gone horribly wrong, let's try a reconnect.
$mysql_errno = 2006;
}
} else {
if ( is_resource( $this->dbh ) ) {
$mysql_errno = mysql_errno( $this->dbh );
} else {
$mysql_errno = 2006;
}
}
}
@ -1743,11 +1753,19 @@ class wpdb {
}
}
// If there is an error then take note of it..
// If there is an error then take note of it.
if ( $this->use_mysqli ) {
if ( $this->dbh instanceof mysqli ) {
$this->last_error = mysqli_error( $this->dbh );
} else {
$this->last_error = __( 'Unable to retrieve the error message from MySQL' );
}
} else {
if ( is_resource( $this->dbh ) ) {
$this->last_error = mysql_error( $this->dbh );
} else {
$this->last_error = __( 'Unable to retrieve the error message from MySQL' );
}
}
if ( $this->last_error ) {