1

Here is the constructor for the wpdb class as found in the source code. According to a google search this has been recently renamed from USE_EXT_MYSQL. However I cannot find anywhere in the source code where either constant is defined.

function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
    register_shutdown_function( array( $this, '__destruct' ) );

    if ( WP_DEBUG && WP_DEBUG_DISPLAY )
        $this->show_errors();

    /* Use ext/mysqli if it exists and:
     *  - WP_USE_EXT_MYSQL is defined as false, or
     *  - We are a development version of WordPress, or
     *  - We are running PHP 5.5 or greater, or
     *  - ext/mysql is not loaded.
     */
    if ( function_exists( 'mysqli_connect' ) ) {
        if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
            $this->use_mysqli = ! WP_USE_EXT_MYSQL;
        } elseif ( version_compare( phpversion(), '5.5', '>=' ) || ! function_exists( 'mysql_connect' ) ) {
            $this->use_mysqli = true;
        } elseif ( false !== strpos( $GLOBALS['wp_version'], '-' ) ) {
            $this->use_mysqli = true;
        }
    }

Can someone please explain to me what the code does and whether there has been an omission somewhere?

Thanks.

3

This constant is actually never defined in core code at all. You can define it yourself in wp-config.php configuration if you need to, but core doesn't need it defined for normal operation. It only exists for re–configuring into running untypical setup.

1

Since WordPress 3.9, WP uses MySQLi as the default connection method when:

  • The MySQLi extension is installed on the webserver AND
    1. The WP_USE_EXT_MYSQL constant is set to false (in the wp-config.php) OR
    2. The webserver runs PHP version 5.5 or later OR
    3. The ext/mysql is not loaded

** Setting the WP_USE_EXT_MYSQL constant to true causes WordPress to use the MySQL extension instead of the MySQLi extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.