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.


Built from https://develop.svn.wordpress.org/trunk@37548


git-svn-id: http://core.svn.wordpress.org/trunk@37516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-05-24 05:24:26 +00:00
parent 6c405b8f36
commit 2441b7b52f
2 changed files with 26 additions and 8 deletions

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-alpha-37547';
$wp_version = '4.6-alpha-37548';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

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 ) {
$mysql_errno = mysqli_errno( $this->dbh );
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 {
$mysql_errno = mysql_errno( $this->dbh );
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 ) {
$this->last_error = mysqli_error( $this->dbh );
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 {
$this->last_error = mysql_error( $this->dbh );
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 ) {