Database: Fall back from ext/mysqli to ext/mysql if the connection fails.
This allows us to avoid breaking a site that works under ext/mysql but is misconfigured for ext/mysqli. props pento. see #21663. git-svn-id: https://develop.svn.wordpress.org/trunk@27935 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
641f9f9a93
commit
ccb4f3714a
@ -548,6 +548,15 @@ class wpdb {
|
||||
*/
|
||||
private $use_mysqli = false;
|
||||
|
||||
/**
|
||||
* Whether we've managed to successfully connect at some point
|
||||
*
|
||||
* @since 3.9.0
|
||||
* @access private
|
||||
* @var bool
|
||||
*/
|
||||
private $has_connected = false;
|
||||
|
||||
/**
|
||||
* Connects to the database server and selects a database
|
||||
*
|
||||
@ -1336,6 +1345,26 @@ class wpdb {
|
||||
|
||||
if ( $this->dbh->connect_errno ) {
|
||||
$this->dbh = null;
|
||||
|
||||
/* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
|
||||
* - We haven't previously connected, and
|
||||
* - USE_EXT_MYSQL isn't set to false, and
|
||||
* - ext/mysql is loaded.
|
||||
*/
|
||||
$attempt_fallback = true;
|
||||
|
||||
if ( $this->has_connected ) {
|
||||
$attempt_fallback = false;
|
||||
} else if ( defined( 'USE_EXT_MYSQL' ) && ! USE_EXT_MYSQL ) {
|
||||
$attempt_fallback = false;
|
||||
} else if ( ! function_exists( 'mysql_connect' ) ) {
|
||||
$attempt_fallback = false;
|
||||
}
|
||||
|
||||
if ( $attempt_fallback ) {
|
||||
$this->use_mysqli = false;
|
||||
$this->db_connect();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( WP_DEBUG ) {
|
||||
@ -1367,6 +1396,7 @@ class wpdb {
|
||||
|
||||
return false;
|
||||
} else if ( $this->dbh ) {
|
||||
$this->has_connected = true;
|
||||
$this->set_charset( $this->dbh );
|
||||
$this->set_sql_mode();
|
||||
$this->ready = true;
|
||||
|
Loading…
Reference in New Issue
Block a user