Make WordPress Core

Changeset 27935


Ignore:
Timestamp:
04/03/2014 09:57:22 PM (11 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

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

    r27925 r27935  
    548548     */
    549549    private $use_mysqli = false;
     550
     551    /**
     552     * Whether we've managed to successfully connect at some point
     553     *
     554     * @since 3.9.0
     555     * @access private
     556     * @var bool
     557     */
     558    private $has_connected = false;
    550559
    551560    /**
     
    13371346            if ( $this->dbh->connect_errno ) {
    13381347                $this->dbh = null;
     1348
     1349                /* It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
     1350                 *  - We haven't previously connected, and
     1351                 *  - USE_EXT_MYSQL isn't set to false, and
     1352                 *  - ext/mysql is loaded.
     1353                 */
     1354                $attempt_fallback = true;
     1355
     1356                if ( $this->has_connected ) {
     1357                    $attempt_fallback = false;
     1358                } else if ( defined( 'USE_EXT_MYSQL' ) && ! USE_EXT_MYSQL ) {
     1359                    $attempt_fallback = false;
     1360                } else if ( ! function_exists( 'mysql_connect' ) ) {
     1361                    $attempt_fallback = false;
     1362                }
     1363
     1364                if ( $attempt_fallback ) {
     1365                    $this->use_mysqli = false;
     1366                    $this->db_connect();
     1367                }
    13391368            }
    13401369        } else {
     
    13681397            return false;
    13691398        } else if ( $this->dbh ) {
     1399            $this->has_connected = true;
    13701400            $this->set_charset( $this->dbh );
    13711401            $this->set_sql_mode();
Note: See TracChangeset for help on using the changeset viewer.