WPDB: Add a `close()` method to `wpdb`, for when the connection needs to be manually closed.

In the event that it was closed prematurely, `wpdb::query()` will re-open the connection automatically.

Fixes #34903.


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


git-svn-id: http://core.svn.wordpress.org/trunk@36400 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-02-02 00:13:26 +00:00
parent 9f7d608a6a
commit 5779ed9d8a
2 changed files with 27 additions and 1 deletions

View File

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

View File

@ -3093,6 +3093,32 @@ class wpdb {
wp_die($message);
}
/**
* Closes the current database connection.
*
* @since 4.5.0
*
* @return bool True if the connection was succesfully closed, false if it wasn't, or the connection doesn't exist.
*/
public function close() {
if ( ! $this->dbh ) {
return false;
}
if ( $this->use_mysqli ) {
$closed = mysqli_close( $this->dbh );
} else {
$closed = mysql_close( $this->dbh );
}
if ( $closed ) {
$this->dbh = null;
}
return $closed;
}
/**
* Whether MySQL database is at least the required minimum version.
*