Make WordPress Core

Changeset 56475


Ignore:
Timestamp:
08/26/2023 01:01:05 PM (3 years ago)
Author:
johnbillion
Message:

Database: Remove support for the mysql extension.

The mysql extension is no longer used in PHP 7 or above. There's a good amount of conditional code in wpdb and the health checks that can be removed now that only the mysqli functions are used.

Fixes #59118

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpcompat.xml.dist

    r56141 r56475  
    8282                <exclude-pattern>/random_compat/random_bytes_mcrypt\.php$</exclude-pattern>
    8383        </rule>
    84 
    85         <!-- Allow the WP DB Class for use of `mysql_` extension in PHP < 7.0. -->
    86         <rule ref="PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved">
    87                 <exclude-pattern>/src/wp-includes/class-wpdb\.php</exclude-pattern>
    88         </rule>
    8984</ruleset>
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r56346 r56475  
    856856
    857857                // Populate the database debug fields.
    858                 if ( is_resource( $wpdb->dbh ) ) {
    859                         // Old mysql extension.
    860                         $extension = 'mysql';
    861                 } elseif ( is_object( $wpdb->dbh ) ) {
     858                if ( is_object( $wpdb->dbh ) ) {
    862859                        // mysqli or PDO.
    863860                        $extension = get_class( $wpdb->dbh );
     
    869866                $server = $wpdb->get_var( 'SELECT VERSION()' );
    870867
    871                 if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
    872                         $client_version = $wpdb->dbh->client_info;
    873                 } else {
    874                         // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    875                         if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
    876                                 $client_version = $matches[0];
    877                         } else {
    878                                 $client_version = null;
    879                         }
    880                 }
     868                $client_version = $wpdb->dbh->client_info;
    881869
    882870                $info['wp-database']['fields']['extension'] = array(
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r56401 r56475  
    13571357                }
    13581358
    1359                 if ( $wpdb->use_mysqli ) {
    1360                         // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info
    1361                         $mysql_client_version = mysqli_get_client_info();
    1362                 } else {
    1363                         // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
    1364                         $mysql_client_version = mysql_get_client_info();
    1365                 }
     1359                // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info
     1360                $mysql_client_version = mysqli_get_client_info();
    13661361
    13671362                /*
  • trunk/src/wp-includes/class-wpdb.php

    r56180 r56475  
    143143         * Possible values:
    144144         *
    145          * - For successful SELECT, SHOW, DESCRIBE, or EXPLAIN queries:
    146          *   - `mysqli_result` instance when the `mysqli` driver is in use
    147          *   - `resource` when the older `mysql` driver is in use
     145         * - `mysqli_result` instance for successful SELECT, SHOW, DESCRIBE, or EXPLAIN queries
    148146         * - `true` for other query types that were successful
    149147         * - `null` if a query is yet to be made or if the result has since been flushed
     
    152150         * @since 0.71
    153151         *
    154          * @var mysqli_result|resource|bool|null
     152         * @var mysqli_result|bool|null
    155153         */
    156154        protected $result;
     
    605603         * Possible values:
    606604         *
    607          * - `mysqli` instance when the `mysqli` driver is in use
    608          * - `resource` when the older `mysql` driver is in use
     605         * - `mysqli` instance during normal operation
    609606         * - `null` if the connection is yet to be made or has been closed
    610607         * - `false` if the connection has failed
     
    612609         * @since 0.71
    613610         *
    614          * @var mysqli|resource|false|null
     611         * @var mysqli|false|null
    615612         */
    616613        protected $dbh;
     
    695692
    696693        /**
    697          * Whether to use mysqli over mysql. Default false.
    698          *
    699          * @since 3.9.0
    700          *
    701          * @var bool
    702          */
    703         private $use_mysqli = false;
    704 
    705         /**
    706694         * Whether we've managed to successfully connect at some point.
    707695         *
     
    750738                if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
    751739                        $this->show_errors();
    752                 }
    753 
    754                 // Use the `mysqli` extension if it exists unless `WP_USE_EXT_MYSQL` is defined as true.
    755                 if ( function_exists( 'mysqli_connect' ) ) {
    756                         $this->use_mysqli = true;
    757 
    758                         if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
    759                                 $this->use_mysqli = ! WP_USE_EXT_MYSQL;
    760                         }
    761740                }
    762741
     
    881860         */
    882861        public function determine_charset( $charset, $collate ) {
    883                 if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) {
     862                if ( ( ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) {
    884863                        return compact( 'charset', 'collate' );
    885864                }
     
    916895         * @since 3.1.0
    917896         *
    918          * @param mysqli|resource $dbh     The connection returned by `mysqli_connect()` or `mysql_connect()`.
    919          * @param string          $charset Optional. The character set. Default null.
    920          * @param string          $collate Optional. The collation. Default null.
     897         * @param mysqli $dbh     The connection returned by `mysqli_connect()`.
     898         * @param string $charset Optional. The character set. Default null.
     899         * @param string $collate Optional. The collation. Default null.
    921900         */
    922901        public function set_charset( $dbh, $charset = null, $collate = null ) {
     
    930909                        $set_charset_succeeded = true;
    931910
    932                         if ( $this->use_mysqli ) {
    933                                 if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
    934                                         $set_charset_succeeded = mysqli_set_charset( $dbh, $charset );
     911                        if ( function_exists( 'mysqli_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
     912                                $set_charset_succeeded = mysqli_set_charset( $dbh, $charset );
     913                        }
     914
     915                        if ( $set_charset_succeeded ) {
     916                                $query = $this->prepare( 'SET NAMES %s', $charset );
     917                                if ( ! empty( $collate ) ) {
     918                                        $query .= $this->prepare( ' COLLATE %s', $collate );
    935919                                }
    936 
    937                                 if ( $set_charset_succeeded ) {
    938                                         $query = $this->prepare( 'SET NAMES %s', $charset );
    939                                         if ( ! empty( $collate ) ) {
    940                                                 $query .= $this->prepare( ' COLLATE %s', $collate );
    941                                         }
    942                                         mysqli_query( $dbh, $query );
    943                                 }
    944                         } else {
    945                                 if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset' ) ) {
    946                                         $set_charset_succeeded = mysql_set_charset( $charset, $dbh );
    947                                 }
    948                                 if ( $set_charset_succeeded ) {
    949                                         $query = $this->prepare( 'SET NAMES %s', $charset );
    950                                         if ( ! empty( $collate ) ) {
    951                                                 $query .= $this->prepare( ' COLLATE %s', $collate );
    952                                         }
    953                                         mysql_query( $query, $dbh );
    954                                 }
     920                                mysqli_query( $dbh, $query );
    955921                        }
    956922                }
     
    968934        public function set_sql_mode( $modes = array() ) {
    969935                if ( empty( $modes ) ) {
    970                         if ( $this->use_mysqli ) {
    971                                 $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );
    972                         } else {
    973                                 $res = mysql_query( 'SELECT @@SESSION.sql_mode', $this->dbh );
    974                         }
     936                        $res = mysqli_query( $this->dbh, 'SELECT @@SESSION.sql_mode' );
    975937
    976938                        if ( empty( $res ) ) {
     
    978940                        }
    979941
    980                         if ( $this->use_mysqli ) {
    981                                 $modes_array = mysqli_fetch_array( $res );
    982                                 if ( empty( $modes_array[0] ) ) {
    983                                         return;
    984                                 }
    985                                 $modes_str = $modes_array[0];
    986                         } else {
    987                                 $modes_str = mysql_result( $res, 0 );
    988                         }
     942                        $modes_array = mysqli_fetch_array( $res );
     943
     944                        if ( empty( $modes_array[0] ) ) {
     945                                return;
     946                        }
     947
     948                        $modes_str = $modes_array[0];
    989949
    990950                        if ( empty( $modes_str ) ) {
     
    1014974                $modes_str = implode( ',', $modes );
    1015975
    1016                 if ( $this->use_mysqli ) {
    1017                         mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" );
    1018                 } else {
    1019                         mysql_query( "SET SESSION sql_mode='$modes_str'", $this->dbh );
    1020                 }
     976                mysqli_query( $this->dbh, "SET SESSION sql_mode='$modes_str'" );
    1021977        }
    1022978
     
    12211177         * @since 0.71
    12221178         *
    1223          * @param string          $db  Database name.
    1224          * @param mysqli|resource $dbh Optional. Database connection.
    1225          *                             Defaults to the current database handle.
     1179         * @param string $db  Database name.
     1180         * @param mysqli $dbh Optional. Database connection.
     1181         *                    Defaults to the current database handle.
    12261182         */
    12271183        public function select( $db, $dbh = null ) {
     
    12301186                }
    12311187
    1232                 if ( $this->use_mysqli ) {
    1233                         $success = mysqli_select_db( $dbh, $db );
    1234                 } else {
    1235                         $success = mysql_select_db( $db, $dbh );
    1236                 }
     1188                $success = mysqli_select_db( $dbh, $db );
     1189
    12371190                if ( ! $success ) {
    12381191                        $this->ready = false;
     
    12981251
    12991252        /**
    1300          * Real escape, using mysqli_real_escape_string() or mysql_real_escape_string().
     1253         * Real escape using mysqli_real_escape_string().
    13011254         *
    13021255         * @since 2.8.0
    13031256         *
    13041257         * @see mysqli_real_escape_string()
    1305          * @see mysql_real_escape_string()
    13061258         *
    13071259         * @param string $data String to escape.
     
    13141266
    13151267                if ( $this->dbh ) {
    1316                         if ( $this->use_mysqli ) {
    1317                                 $escaped = mysqli_real_escape_string( $this->dbh, $data );
    1318                         } else {
    1319                                 $escaped = mysql_real_escape_string( $data, $this->dbh );
    1320                         }
     1268                        $escaped = mysqli_real_escape_string( $this->dbh, $data );
    13211269                } else {
    13221270                        $class = get_class( $this );
     
    18371785
    18381786                if ( ! $str ) {
    1839                         if ( $this->use_mysqli ) {
    1840                                 $str = mysqli_error( $this->dbh );
    1841                         } else {
    1842                                 $str = mysql_error( $this->dbh );
    1843                         }
    1844                 }
     1787                        $str = mysqli_error( $this->dbh );
     1788                }
     1789
    18451790                $EZSQL_ERROR[] = array(
    18461791                        'query'     => $this->last_query,
     
    19641909                $this->last_error    = '';
    19651910
    1966                 if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
     1911                if ( $this->result instanceof mysqli_result ) {
    19671912                        mysqli_free_result( $this->result );
    19681913                        $this->result = null;
     
    19771922                                mysqli_next_result( $this->dbh );
    19781923                        }
    1979                 } elseif ( is_resource( $this->result ) ) {
    1980                         mysql_free_result( $this->result );
    19811924                }
    19821925        }
     
    19961939                $this->is_mysql = true;
    19971940
     1941                $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
     1942
    19981943                /*
    1999                  * Deprecated in 3.9+ when using MySQLi. No equivalent
    2000                  * $new_link parameter exists for mysqli_* functions.
     1944                 * Set the MySQLi error reporting off because WordPress handles its own.
     1945                 * This is due to the default value change from `MYSQLI_REPORT_OFF`
     1946                 * to `MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT` in PHP 8.1.
    20011947                 */
    2002                 $new_link     = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
    2003                 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
    2004 
    2005                 if ( $this->use_mysqli ) {
    2006                         /*
    2007                          * Set the MySQLi error reporting off because WordPress handles its own.
    2008                          * This is due to the default value change from `MYSQLI_REPORT_OFF`
    2009                          * to `MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT` in PHP 8.1.
    2010                          */
    2011                         mysqli_report( MYSQLI_REPORT_OFF );
    2012 
    2013                         $this->dbh = mysqli_init();
    2014 
    2015                         $host    = $this->dbhost;
    2016                         $port    = null;
    2017                         $socket  = null;
    2018                         $is_ipv6 = false;
    2019 
    2020                         $host_data = $this->parse_db_host( $this->dbhost );
    2021                         if ( $host_data ) {
    2022                                 list( $host, $port, $socket, $is_ipv6 ) = $host_data;
    2023                         }
    2024 
    2025                         /*
    2026                          * If using the `mysqlnd` library, the IPv6 address needs to be enclosed
    2027                          * in square brackets, whereas it doesn't while using the `libmysqlclient` library.
    2028                          * @see https://bugs.php.net/bug.php?id=67563
    2029                          */
    2030                         if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
    2031                                 $host = "[$host]";
    2032                         }
    2033 
    2034                         if ( WP_DEBUG ) {
    2035                                 mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
    2036                         } else {
    2037                                 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    2038                                 @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
    2039                         }
    2040 
    2041                         if ( $this->dbh->connect_errno ) {
    2042                                 $this->dbh = null;
    2043 
    2044                                 /*
    2045                                  * It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if:
    2046                                  *  - We haven't previously connected, and
    2047                                  *  - WP_USE_EXT_MYSQL isn't set to false, and
    2048                                  *  - ext/mysql is loaded.
    2049                                  */
    2050                                 $attempt_fallback = true;
    2051 
    2052                                 if ( $this->has_connected ) {
    2053                                         $attempt_fallback = false;
    2054                                 } elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) {
    2055                                         $attempt_fallback = false;
    2056                                 } elseif ( ! function_exists( 'mysql_connect' ) ) {
    2057                                         $attempt_fallback = false;
    2058                                 }
    2059 
    2060                                 if ( $attempt_fallback ) {
    2061                                         $this->use_mysqli = false;
    2062                                         return $this->db_connect( $allow_bail );
    2063                                 }
    2064                         }
     1948                mysqli_report( MYSQLI_REPORT_OFF );
     1949
     1950                $this->dbh = mysqli_init();
     1951
     1952                $host    = $this->dbhost;
     1953                $port    = null;
     1954                $socket  = null;
     1955                $is_ipv6 = false;
     1956
     1957                $host_data = $this->parse_db_host( $this->dbhost );
     1958                if ( $host_data ) {
     1959                        list( $host, $port, $socket, $is_ipv6 ) = $host_data;
     1960                }
     1961
     1962                /*
     1963                 * If using the `mysqlnd` library, the IPv6 address needs to be enclosed
     1964                 * in square brackets, whereas it doesn't while using the `libmysqlclient` library.
     1965                 * @see https://bugs.php.net/bug.php?id=67563
     1966                 */
     1967                if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
     1968                        $host = "[$host]";
     1969                }
     1970
     1971                if ( WP_DEBUG ) {
     1972                        mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
    20651973                } else {
    2066                         if ( WP_DEBUG ) {
    2067                                 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
    2068                         } else {
    2069                                 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
    2070                                 $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
    2071                         }
     1974                        // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
     1975                        @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
     1976                }
     1977
     1978                if ( $this->dbh->connect_errno ) {
     1979                        $this->dbh = null;
    20721980                }
    20731981
     
    21972105         */
    21982106        public function check_connection( $allow_bail = true ) {
    2199                 if ( $this->use_mysqli ) {
    2200                         if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
    2201                                 return true;
    2202                         }
    2203                 } else {
    2204                         if ( ! empty( $this->dbh ) && mysql_ping( $this->dbh ) ) {
    2205                                 return true;
    2206                         }
     2107                if ( ! empty( $this->dbh ) && mysqli_ping( $this->dbh ) ) {
     2108                        return true;
    22072109                }
    22082110
     
    23482250                // Database server has gone away, try to reconnect.
    23492251                $mysql_errno = 0;
    2350                 if ( ! empty( $this->dbh ) ) {
    2351                         if ( $this->use_mysqli ) {
    2352                                 if ( $this->dbh instanceof mysqli ) {
    2353                                         $mysql_errno = mysqli_errno( $this->dbh );
    2354                                 } else {
    2355                                         /*
    2356                                          * $dbh is defined, but isn't a real connection.
    2357                                          * Something has gone horribly wrong, let's try a reconnect.
    2358                                          */
    2359                                         $mysql_errno = 2006;
    2360                                 }
    2361                         } else {
    2362                                 if ( is_resource( $this->dbh ) ) {
    2363                                         $mysql_errno = mysql_errno( $this->dbh );
    2364                                 } else {
    2365                                         $mysql_errno = 2006;
    2366                                 }
    2367                         }
     2252
     2253                if ( $this->dbh instanceof mysqli ) {
     2254                        $mysql_errno = mysqli_errno( $this->dbh );
     2255                } else {
     2256                        /*
     2257                         * $dbh is defined, but isn't a real connection.
     2258                         * Something has gone horribly wrong, let's try a reconnect.
     2259                         */
     2260                        $mysql_errno = 2006;
    23682261                }
    23692262
     
    23782271
    23792272                // If there is an error then take note of it.
    2380                 if ( $this->use_mysqli ) {
    2381                         if ( $this->dbh instanceof mysqli ) {
    2382                                 $this->last_error = mysqli_error( $this->dbh );
    2383                         } else {
    2384                                 $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
    2385                         }
     2273                if ( $this->dbh instanceof mysqli ) {
     2274                        $this->last_error = mysqli_error( $this->dbh );
    23862275                } else {
    2387                         if ( is_resource( $this->dbh ) ) {
    2388                                 $this->last_error = mysql_error( $this->dbh );
    2389                         } else {
    2390                                 $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
    2391                         }
     2276                        $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
    23922277                }
    23932278
     
    24052290                        $return_val = $this->result;
    24062291                } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) {
    2407                         if ( $this->use_mysqli ) {
    2408                                 $this->rows_affected = mysqli_affected_rows( $this->dbh );
    2409                         } else {
    2410                                 $this->rows_affected = mysql_affected_rows( $this->dbh );
    2411                         }
     2292                        $this->rows_affected = mysqli_affected_rows( $this->dbh );
     2293
    24122294                        // Take note of the insert_id.
    24132295                        if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
    2414                                 if ( $this->use_mysqli ) {
    2415                                         $this->insert_id = mysqli_insert_id( $this->dbh );
    2416                                 } else {
    2417                                         $this->insert_id = mysql_insert_id( $this->dbh );
    2418                                 }
    2419                         }
     2296                                $this->insert_id = mysqli_insert_id( $this->dbh );
     2297                        }
     2298
    24202299                        // Return number of rows affected.
    24212300                        $return_val = $this->rows_affected;
    24222301                } else {
    24232302                        $num_rows = 0;
    2424                         if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
     2303
     2304                        if ( $this->result instanceof mysqli_result ) {
    24252305                                while ( $row = mysqli_fetch_object( $this->result ) ) {
    24262306                                        $this->last_result[ $num_rows ] = $row;
    24272307                                        $num_rows++;
    24282308                                }
    2429                         } elseif ( is_resource( $this->result ) ) {
    2430                                 while ( $row = mysql_fetch_object( $this->result ) ) {
    2431                                         $this->last_result[ $num_rows ] = $row;
    2432                                         $num_rows++;
    2433                                 }
    24342309                        }
    24352310
     
    24432318
    24442319        /**
    2445          * Internal function to perform the mysql_query() call.
     2320         * Internal function to perform the mysqli_query() call.
    24462321         *
    24472322         * @since 3.9.0
     
    24562331                }
    24572332
    2458                 if ( ! empty( $this->dbh ) && $this->use_mysqli ) {
     2333                if ( ! empty( $this->dbh ) ) {
    24592334                        $this->result = mysqli_query( $this->dbh, $query );
    2460                 } elseif ( ! empty( $this->dbh ) ) {
    2461                         $this->result = mysql_query( $query, $this->dbh );
    2462                 }
     2335                }
     2336
    24632337                $this->num_queries++;
    24642338
     
    36373511                                                $connection_charset = $this->charset;
    36383512                                        } else {
    3639                                                 if ( $this->use_mysqli ) {
    3640                                                         $connection_charset = mysqli_character_set_name( $this->dbh );
    3641                                                 } else {
    3642                                                         $connection_charset = mysql_client_encoding();
    3643                                                 }
     3513                                                $connection_charset = mysqli_character_set_name( $this->dbh );
    36443514                                        }
    36453515
     
    38513721                }
    38523722
    3853                 if ( $this->use_mysqli ) {
    3854                         $num_fields = mysqli_num_fields( $this->result );
    3855                         for ( $i = 0; $i < $num_fields; $i++ ) {
    3856                                 $this->col_info[ $i ] = mysqli_fetch_field( $this->result );
    3857                         }
    3858                 } else {
    3859                         $num_fields = mysql_num_fields( $this->result );
    3860                         for ( $i = 0; $i < $num_fields; $i++ ) {
    3861                                 $this->col_info[ $i ] = mysql_fetch_field( $this->result, $i );
    3862                         }
     3723                $num_fields = mysqli_num_fields( $this->result );
     3724
     3725                for ( $i = 0; $i < $num_fields; $i++ ) {
     3726                        $this->col_info[ $i ] = mysqli_fetch_field( $this->result );
    38633727                }
    38643728        }
     
    39333797                        $error = '';
    39343798
    3935                         if ( $this->use_mysqli ) {
    3936                                 if ( $this->dbh instanceof mysqli ) {
    3937                                         $error = mysqli_error( $this->dbh );
    3938                                 } elseif ( mysqli_connect_errno() ) {
    3939                                         $error = mysqli_connect_error();
    3940                                 }
    3941                         } else {
    3942                                 if ( is_resource( $this->dbh ) ) {
    3943                                         $error = mysql_error( $this->dbh );
    3944                                 } else {
    3945                                         $error = mysql_error();
    3946                                 }
     3799                        if ( $this->dbh instanceof mysqli ) {
     3800                                $error = mysqli_error( $this->dbh );
     3801                        } elseif ( mysqli_connect_errno() ) {
     3802                                $error = mysqli_connect_error();
    39473803                        }
    39483804
     
    39763832                }
    39773833
    3978                 if ( $this->use_mysqli ) {
    3979                         $closed = mysqli_close( $this->dbh );
    3980                 } else {
    3981                         $closed = mysql_close( $this->dbh );
    3982                 }
     3834                $closed = mysqli_close( $this->dbh );
    39833835
    39843836                if ( $closed ) {
     
    40993951                                        return false;
    41003952                                }
    4101                                 if ( $this->use_mysqli ) {
    4102                                         $client_version = mysqli_get_client_info();
    4103                                 } else {
    4104                                         $client_version = mysql_get_client_info();
    4105                                 }
     3953
     3954                                $client_version = mysqli_get_client_info();
    41063955
    41073956                                /*
     
    41554004
    41564005        /**
    4157          * Retrieves full database server information.
     4006         * Returns the version of the MySQL server.
    41584007         *
    41594008         * @since 5.5.0
    41604009         *
    4161          * @return string|false Server info on success, false on failure.
     4010         * @return string Server version as a string.
    41624011         */
    41634012        public function db_server_info() {
    4164                 if ( $this->use_mysqli ) {
    4165                         $server_info = mysqli_get_server_info( $this->dbh );
    4166                 } else {
    4167                         $server_info = mysql_get_server_info( $this->dbh );
    4168                 }
    4169 
    4170                 return $server_info;
     4013                return mysqli_get_server_info( $this->dbh );
    41714014        }
    41724015}
  • trunk/src/wp-includes/load.php

    r56249 r56475  
    135135
    136136/**
    137  * Checks for the required PHP version, and the MySQL extension or
     137 * Checks for the required PHP version, and the mysqli extension or
    138138 * a database drop-in.
    139139 *
     
    167167        $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
    168168
    169         if ( ! function_exists( 'mysqli_connect' ) && ! function_exists( 'mysql_connect' )
     169        if ( ! function_exists( 'mysqli_connect' )
    170170                && ! file_exists( $wp_content_dir . '/db.php' )
    171171        ) {
  • trunk/tests/phpunit/includes/utils.php

    r55028 r56475  
    557557                global $wpdb;
    558558                $this->dbh         = $wpdb->dbh;
    559                 $this->use_mysqli  = $wpdb->use_mysqli;
    560559                $this->is_mysql    = $wpdb->is_mysql;
    561560                $this->ready       = true;
  • trunk/tests/phpunit/tests/db.php

    r55562 r56475  
    714714        public function test_mysqli_flush_sync() {
    715715                global $wpdb;
    716                 if ( ! $wpdb->use_mysqli ) {
    717                         $this->markTestSkipped( 'mysqli not being used.' );
    718                 }
    719716
    720717                $suppress = $wpdb->suppress_errors( true );
Note: See TracChangeset for help on using the changeset viewer.