Make WordPress Core

Ticket #41956: 41956.diff

File 41956.diff, 61.0 KB (added by munyagu, 7 years ago)
  • src/wp-includes/wp-db.php

     
    208208         * @since 3.0.0
    209209         * @var string
    210210         */
    211          public $base_prefix;
     211        public $base_prefix;
    212212
    213213        /**
    214214         * Whether the database queries are ready to start executing.
     
    241241         * @see wpdb::tables()
    242242         * @var array
    243243         */
    244         var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',
    245                 'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta' );
     244        var $tables = array(
     245                'posts',
     246                'comments',
     247                'links',
     248                'options',
     249                'postmeta',
     250                'terms',
     251                'term_taxonomy',
     252                'term_relationships',
     253                'termmeta',
     254                'commentmeta'
     255        );
    246256
    247257        /**
    248258         * List of deprecated WordPress tables
     
    271281         * @see wpdb::tables()
    272282         * @var array
    273283         */
    274         var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',
    275                 'sitecategories', 'registration_log', 'blog_versions' );
     284        var $ms_global_tables = array(
     285                'blogs',
     286                'signups',
     287                'site',
     288                'sitemeta',
     289                'sitecategories',
     290                'registration_log',
     291                'blog_versions'
     292        );
    276293
    277294        /**
    278295         * WordPress Comments table
     
    528545         * @since 3.9.0
    529546         * @var array
    530547         */
    531         protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY',
    532                 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' );
     548        protected $incompatible_modes = array(
     549                'NO_ZERO_DATE',
     550                'ONLY_FULL_GROUP_BY',
     551                'STRICT_TRANS_TABLES',
     552                'STRICT_ALL_TABLES',
     553                'TRADITIONAL'
     554        );
    533555
    534556        /**
    535557         * Whether to use mysqli over mysql.
     
    559581         *
    560582         * @global string $wp_version
    561583         *
    562          * @param string $dbuser     MySQL database user
     584         * @param string $dbuser MySQL database user
    563585         * @param string $dbpassword MySQL database password
    564          * @param string $dbname     MySQL database name
    565          * @param string $dbhost     MySQL database host
     586         * @param string $dbname MySQL database name
     587         * @param string $dbhost MySQL database host
    566588         */
    567589        public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
    568590                register_shutdown_function( array( $this, '__destruct' ) );
    569591
    570                 if ( WP_DEBUG && WP_DEBUG_DISPLAY )
     592                if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
    571593                        $this->show_errors();
     594                }
    572595
    573596                /* Use ext/mysqli if it exists and:
    574597                 *  - WP_USE_EXT_MYSQL is defined as false, or
     
    586609                        }
    587610                }
    588611
    589                 $this->dbuser = $dbuser;
     612                $this->dbuser     = $dbuser;
    590613                $this->dbpassword = $dbpassword;
    591                 $this->dbname = $dbname;
    592                 $this->dbhost = $dbhost;
     614                $this->dbname     = $dbname;
     615                $this->dbhost     = $dbhost;
    593616
    594617                // wp-config.php creation will manually connect when ready.
    595618                if ( defined( 'WP_SETUP_CONFIG' ) ) {
     
    616639         * @since 3.5.0
    617640         *
    618641         * @param string $name The private member to get, and optionally process
     642         *
    619643         * @return mixed The private member
    620644         */
    621645        public function __get( $name ) {
    622                 if ( 'col_info' === $name )
     646                if ( 'col_info' === $name ) {
    623647                        $this->load_col_info();
     648                }
    624649
    625650                return $this->$name;
    626651        }
     
    630655         *
    631656         * @since 3.5.0
    632657         *
    633          * @param string $name  The private member to set
    634          * @param mixed  $value The value to set
     658         * @param string $name The private member to set
     659         * @param mixed $value The value to set
    635660         */
    636661        public function __set( $name, $value ) {
    637662                $protected_members = array(
     
    639664                        'table_charset',
    640665                        'check_current_query',
    641666                );
    642                 if (  in_array( $name, $protected_members, true ) ) {
     667                if ( in_array( $name, $protected_members, true ) ) {
    643668                        return;
    644669                }
    645670                $this->$name = $value;
     
    650675         *
    651676         * @since 3.5.0
    652677         *
    653          * @param string $name  The private member to check
     678         * @param string $name The private member to check
    654679         *
    655680         * @return bool If the member is set or not
    656681         */
     
    663688         *
    664689         * @since 3.5.0
    665690         *
    666          * @param string $name  The private member to unset
     691         * @param string $name The private member to unset
    667692         */
    668693        public function __unset( $name ) {
    669694                unset( $this->$name );
     
    678703                $charset = '';
    679704                $collate = '';
    680705
    681                 if ( function_exists('is_multisite') && is_multisite() ) {
     706                if ( function_exists( 'is_multisite' ) && is_multisite() ) {
    682707                        $charset = 'utf8';
    683708                        if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
    684709                                $collate = DB_COLLATE;
     
    708733         *
    709734         * @param string $charset The character set to check.
    710735         * @param string $collate The collation to check.
     736         *
    711737         * @return array The most appropriate character set and collation to use.
    712738         */
    713739        public function determine_charset( $charset, $collate ) {
     
    746772         *
    747773         * @since 3.1.0
    748774         *
    749          * @param resource $dbh     The resource given by mysql_connect
    750          * @param string   $charset Optional. The character set. Default null.
    751          * @param string   $collate Optional. The collation. Default null.
     775         * @param resource $dbh The resource given by mysql_connect
     776         * @param string $charset Optional. The character set. Default null.
     777         * @param string $collate Optional. The collation. Default null.
    752778         */
    753779        public function set_charset( $dbh, $charset = null, $collate = null ) {
    754                 if ( ! isset( $charset ) )
     780                if ( ! isset( $charset ) ) {
    755781                        $charset = $this->charset;
    756                 if ( ! isset( $collate ) )
     782                }
     783                if ( ! isset( $collate ) ) {
    757784                        $collate = $this->collate;
     785                }
    758786                if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) {
    759787                        $set_charset_succeeded = true;
    760788
     
    765793
    766794                                if ( $set_charset_succeeded ) {
    767795                                        $query = $this->prepare( 'SET NAMES %s', $charset );
    768                                         if ( ! empty( $collate ) )
     796                                        if ( ! empty( $collate ) ) {
    769797                                                $query .= $this->prepare( ' COLLATE %s', $collate );
     798                                        }
    770799                                        mysqli_query( $dbh, $query );
    771800                                }
    772801                        } else {
     
    775804                                }
    776805                                if ( $set_charset_succeeded ) {
    777806                                        $query = $this->prepare( 'SET NAMES %s', $charset );
    778                                         if ( ! empty( $collate ) )
     807                                        if ( ! empty( $collate ) ) {
    779808                                                $query .= $this->prepare( ' COLLATE %s', $collate );
     809                                        }
    780810                                        mysql_query( $query, $dbh );
    781811                                }
    782812                        }
     
    853883         *
    854884         * @since 2.5.0
    855885         *
    856          * @param string $prefix          Alphanumeric name for the new prefix.
    857          * @param bool   $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not.
     886         * @param string $prefix Alphanumeric name for the new prefix.
     887         * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not.
     888         *
    858889         * @return string|WP_Error Old prefix or WP_Error on error
    859890         */
    860891        public function set_prefix( $prefix, $set_table_names = true ) {
    861892
    862                 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
    863                         return new WP_Error('invalid_db_prefix', 'Invalid database prefix' );
     893                if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) {
     894                        return new WP_Error( 'invalid_db_prefix', 'Invalid database prefix' );
     895                }
    864896
    865897                $old_prefix = is_multisite() ? '' : $prefix;
    866898
    867                 if ( isset( $this->base_prefix ) )
     899                if ( isset( $this->base_prefix ) ) {
    868900                        $old_prefix = $this->base_prefix;
     901                }
    869902
    870903                $this->base_prefix = $prefix;
    871904
    872905                if ( $set_table_names ) {
    873                         foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
     906                        foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) {
    874907                                $this->$table = $prefixed_table;
     908                        }
    875909
    876                         if ( is_multisite() && empty( $this->blogid ) )
     910                        if ( is_multisite() && empty( $this->blogid ) ) {
    877911                                return $old_prefix;
     912                        }
    878913
    879914                        $this->prefix = $this->get_blog_prefix();
    880915
    881                         foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
     916                        foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
    882917                                $this->$table = $prefixed_table;
     918                        }
    883919
    884                         foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
     920                        foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
    885921                                $this->$table = $prefixed_table;
     922                        }
    886923                }
     924
    887925                return $old_prefix;
    888926        }
    889927
     
    894932         *
    895933         * @param int $blog_id
    896934         * @param int $network_id Optional.
     935         *
    897936         * @return int previous blog id
    898937         */
    899938        public function set_blog_id( $blog_id, $network_id = 0 ) {
     
    906945
    907946                $this->prefix = $this->get_blog_prefix();
    908947
    909                 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
     948                foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) {
    910949                        $this->$table = $prefixed_table;
     950                }
    911951
    912                 foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
     952                foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) {
    913953                        $this->$table = $prefixed_table;
     954                }
    914955
    915956                return $old_blog_id;
    916957        }
     
    919960         * Gets blog prefix.
    920961         *
    921962         * @since 3.0.0
     963         *
    922964         * @param int $blog_id Optional.
     965         *
    923966         * @return string Blog prefix.
    924967         */
    925968        public function get_blog_prefix( $blog_id = null ) {
    926969                if ( is_multisite() ) {
    927                         if ( null === $blog_id )
     970                        if ( null === $blog_id ) {
    928971                                $blog_id = $this->blogid;
     972                        }
    929973                        $blog_id = (int) $blog_id;
    930                         if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) )
     974                        if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) {
    931975                                return $this->base_prefix;
    932                         else
     976                        } else {
    933977                                return $this->base_prefix . $blog_id . '_';
     978                        }
    934979                } else {
    935980                        return $this->base_prefix;
    936981                }
     
    9571002         * @uses wpdb::$global_tables
    9581003         * @uses wpdb::$ms_global_tables
    9591004         *
    960          * @param string $scope   Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all.
    961          * @param bool   $prefix Optional. Whether to include table prefixes. Default true. If blog
     1005         * @param string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all.
     1006         * @param bool $prefix Optional. Whether to include table prefixes. Default true. If blog
    9621007         *                        prefix is requested, then the custom users and usermeta tables will be mapped.
    963          * @param int    $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested.
     1008         * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested.
     1009         *
    9641010         * @return array Table names. When a prefix is requested, the key is the unprefixed table name.
    9651011         */
    9661012        public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
     
    9671013                switch ( $scope ) {
    9681014                        case 'all' :
    9691015                                $tables = array_merge( $this->global_tables, $this->tables );
    970                                 if ( is_multisite() )
     1016                                if ( is_multisite() ) {
    9711017                                        $tables = array_merge( $tables, $this->ms_global_tables );
     1018                                }
    9721019                                break;
    9731020                        case 'blog' :
    9741021                                $tables = $this->tables;
     
    9751022                                break;
    9761023                        case 'global' :
    9771024                                $tables = $this->global_tables;
    978                                 if ( is_multisite() )
     1025                                if ( is_multisite() ) {
    9791026                                        $tables = array_merge( $tables, $this->ms_global_tables );
     1027                                }
    9801028                                break;
    9811029                        case 'ms_global' :
    9821030                                $tables = $this->ms_global_tables;
     
    9891037                }
    9901038
    9911039                if ( $prefix ) {
    992                         if ( ! $blog_id )
     1040                        if ( ! $blog_id ) {
    9931041                                $blog_id = $this->blogid;
    994                         $blog_prefix = $this->get_blog_prefix( $blog_id );
    995                         $base_prefix = $this->base_prefix;
     1042                        }
     1043                        $blog_prefix   = $this->get_blog_prefix( $blog_id );
     1044                        $base_prefix   = $this->base_prefix;
    9961045                        $global_tables = array_merge( $this->global_tables, $this->ms_global_tables );
    9971046                        foreach ( $tables as $k => $table ) {
    998                                 if ( in_array( $table, $global_tables ) )
     1047                                if ( in_array( $table, $global_tables ) ) {
    9991048                                        $tables[ $table ] = $base_prefix . $table;
    1000                                 else
     1049                                } else {
    10011050                                        $tables[ $table ] = $blog_prefix . $table;
     1051                                }
    10021052                                unset( $tables[ $k ] );
    10031053                        }
    10041054
    1005                         if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) )
     1055                        if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) {
    10061056                                $tables['users'] = CUSTOM_USER_TABLE;
     1057                        }
    10071058
    1008                         if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) )
     1059                        if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) {
    10091060                                $tables['usermeta'] = CUSTOM_USER_META_TABLE;
     1061                        }
    10101062                }
    10111063
    10121064                return $tables;
     
    10201072         *
    10211073         * @since 0.71
    10221074         *
    1023          * @param string        $db MySQL database name
     1075         * @param string $db MySQL database name
    10241076         * @param resource|null $dbh Optional link identifier.
    10251077         */
    10261078        public function select( $db, $dbh = null ) {
    1027                 if ( is_null($dbh) )
     1079                if ( is_null( $dbh ) ) {
    10281080                        $dbh = $this->dbh;
     1081                }
    10291082
    10301083                if ( $this->use_mysqli ) {
    10311084                        $success = mysqli_select_db( $dbh, $db );
     
    10411094
    10421095                                $message .= '<p>' . sprintf(
    10431096                                        /* translators: %s: database name */
    1044                                         __( 'We were able to connect to the database server (which means your username and password is okay) but not able to select the %s database.' ),
    1045                                         '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
    1046                                 ) . "</p>\n";
     1097                                                __( 'We were able to connect to the database server (which means your username and password is okay) but not able to select the %s database.' ),
     1098                                                '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
     1099                                        ) . "</p>\n";
    10471100
    10481101                                $message .= "<ul>\n";
    10491102                                $message .= '<li>' . __( 'Are you sure it exists?' ) . "</li>\n";
     
    10501103
    10511104                                $message .= '<li>' . sprintf(
    10521105                                        /* translators: 1: database user, 2: database name */
    1053                                         __( 'Does the user %1$s have permission to use the %2$s database?' ),
    1054                                         '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) . '</code>',
    1055                                         '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
    1056                                 ) . "</li>\n";
     1106                                                __( 'Does the user %1$s have permission to use the %2$s database?' ),
     1107                                                '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) . '</code>',
     1108                                                '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>'
     1109                                        ) . "</li>\n";
    10571110
    10581111                                $message .= '<li>' . sprintf(
    10591112                                        /* translators: %s: database name */
    1060                                         __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ),
    1061                                         htmlspecialchars( $db, ENT_QUOTES )
    1062                                 ). "</li>\n";
     1113                                                __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ),
     1114                                                htmlspecialchars( $db, ENT_QUOTES )
     1115                                        ) . "</li>\n";
    10631116
    10641117                                $message .= "</ul>\n";
    10651118
    10661119                                $message .= '<p>' . sprintf(
    10671120                                        /* translators: %s: support forums URL */
    1068                                         __( 'If you don&#8217;t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="%s">WordPress Support Forums</a>.' ),
    1069                                         __( 'https://wordpress.org/support/' )
    1070                                 ) . "</p>\n";
     1121                                                __( 'If you don&#8217;t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="%s">WordPress Support Forums</a>.' ),
     1122                                                __( 'https://wordpress.org/support/' )
     1123                                        ) . "</p>\n";
    10711124
    10721125                                $this->bail( $message, 'db_select_fail' );
    10731126                        }
     
    10851138         * @see esc_sql()
    10861139         *
    10871140         * @param string $string
     1141         *
    10881142         * @return string
    10891143         */
    10901144        function _weak_escape( $string ) {
    1091                 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) )
     1145                if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
    10921146                        _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
     1147                }
     1148
    10931149                return addslashes( $string );
    10941150        }
    10951151
     
    11011157         * @since 2.8.0
    11021158         *
    11031159         * @param  string $string to escape
     1160         *
    11041161         * @return string escaped
    11051162         */
    11061163        function _real_escape( $string ) {
     
    11191176                } else {
    11201177                        _doing_it_wrong( $class, sprintf( '%s must set a database connection for use with escaping.', $class ), '3.6.0' );
    11211178                }
     1179
    11221180                return addslashes( $string );
    11231181        }
    11241182
     
    11291187         * @since  2.8.0
    11301188         *
    11311189         * @param  string|array $data
     1190         *
    11321191         * @return string|array escaped
    11331192         */
    11341193        public function _escape( $data ) {
     
    11351194                if ( is_array( $data ) ) {
    11361195                        foreach ( $data as $k => $v ) {
    11371196                                if ( is_array( $v ) ) {
    1138                                         $data[$k] = $this->_escape( $v );
     1197                                        $data[ $k ] = $this->_escape( $v );
    11391198                                } else {
    1140                                         $data[$k] = $this->_real_escape( $v );
     1199                                        $data[ $k ] = $this->_real_escape( $v );
    11411200                                }
    11421201                        }
    11431202                } else {
     
    11581217         * @see esc_sql()
    11591218         *
    11601219         * @param mixed $data
     1220         *
    11611221         * @return mixed
    11621222         */
    11631223        public function escape( $data ) {
    1164                 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) )
     1224                if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) {
    11651225                        _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' );
     1226                }
    11661227                if ( is_array( $data ) ) {
    11671228                        foreach ( $data as $k => $v ) {
    1168                                 if ( is_array( $v ) )
    1169                                         $data[$k] = $this->escape( $v, 'recursive' );
    1170                                 else
    1171                                         $data[$k] = $this->_weak_escape( $v, 'internal' );
     1229                                if ( is_array( $v ) ) {
     1230                                        $data[ $k ] = $this->escape( $v, 'recursive' );
     1231                                } else {
     1232                                        $data[ $k ] = $this->_weak_escape( $v, 'internal' );
     1233                                }
    11721234                        }
    11731235                } else {
    11741236                        $data = $this->_weak_escape( $data, 'internal' );
     
    11871249         * @param string $string to escape
    11881250         */
    11891251        public function escape_by_ref( &$string ) {
    1190                 if ( ! is_float( $string ) )
     1252                if ( ! is_float( $string ) ) {
    11911253                        $string = $this->_real_escape( $string );
     1254                }
    11921255        }
    11931256
    11941257        /**
     
    12171280         * @link https://secure.php.net/sprintf Description of syntax.
    12181281         * @since 2.3.0
    12191282         *
    1220          * @param string      $query    Query statement with sprintf()-like placeholders
    1221          * @param array|mixed $args     The array of variables to substitute into the query's placeholders if being called like
     1283         * @param string $query Query statement with sprintf()-like placeholders
     1284         * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like
    12221285         *                              {@link https://secure.php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if
    12231286         *                              being called like {@link https://secure.php.net/sprintf sprintf()}.
    1224          * @param mixed       $args,... further variables to substitute into the query's placeholders if being called like
     1287         * @param mixed $args,... further variables to substitute into the query's placeholders if being called like
    12251288         *                              {@link https://secure.php.net/sprintf sprintf()}.
     1289         *
    12261290         * @return string|void Sanitized query string, if there is a query to prepare.
    12271291         */
    12281292        public function prepare( $query, $args ) {
    1229                 if ( is_null( $query ) )
     1293                if ( is_null( $query ) ) {
    12301294                        return;
     1295                }
    12311296
    12321297                // This is not meant to be foolproof -- but it will catch obviously incorrect usage.
    12331298                if ( strpos( $query, '%' ) === false ) {
     
    12501315
    12511316                $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
    12521317                $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
    1253                 $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware
     1318                $query = preg_replace( '|(?<!%)%f|', '%F', $query ); // Force floats to be locale unaware
    12541319                $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
    12551320                $query = preg_replace( '/%(?:%|$|([^dsF]))/', '%%\\1', $query ); // escape any unescaped percents
    12561321                array_walk( $args, array( $this, 'escape_by_ref' ) );
     1322
    12571323                return @vsprintf( $query, $args );
    12581324        }
    12591325
     
    12771343         *
    12781344         * @param string $text The raw text to be escaped. The input typed by the user should have no
    12791345         *                     extra or deleted slashes.
     1346         *
    12801347         * @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
    12811348         *                or real_escape next.
    12821349         */
     
    12911358         * @global array $EZSQL_ERROR Stores error information of query and error string
    12921359         *
    12931360         * @param string $str The error to display
     1361         *
    12941362         * @return false|void False if the showing of errors is disabled.
    12951363         */
    12961364        public function print_error( $str = '' ) {
    12971365                global $EZSQL_ERROR;
    12981366
    1299                 if ( !$str ) {
     1367                if ( ! $str ) {
    13001368                        if ( $this->use_mysqli ) {
    1301                                 $str = mysqli_error( $this->dbh );
     1369                                $str = $this->get_error();
    13021370                        } else {
    13031371                                $str = mysql_error( $this->dbh );
    13041372                        }
     
    13051373                }
    13061374                $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );
    13071375
    1308                 if ( $this->suppress_errors )
     1376                if ( $this->suppress_errors ) {
    13091377                        return false;
     1378                }
    13101379
    13111380                wp_load_translations_early();
    13121381
     
    13211390                error_log( $error_str );
    13221391
    13231392                // Are we showing errors?
    1324                 if ( ! $this->show_errors )
     1393                if ( ! $this->show_errors ) {
    13251394                        return false;
     1395                }
    13261396
    13271397                // If there is an error then take note of it
    13281398                if ( is_multisite() ) {
     
    13531423        }
    13541424
    13551425        /**
     1426         * Gets database error.
     1427         *
     1428         * @return string Error code and message.
     1429         */
     1430        public function get_error() {
     1431                $error_code = mysqli_errno( $this->dbh );
     1432                $error      = '';
     1433                if ( $error_code !== 0 ) {
     1434                        $error = sprintf( 'code:"%s",message:"%s"',
     1435                                mysqli_errno( $this->dbh ),
     1436                                mysqli_error( $this->dbh )
     1437                        );
     1438                }
     1439
     1440                return $error;
     1441        }
     1442
     1443        /**
    13561444         * Enables showing of database errors.
    13571445         *
    13581446         * This function should be used only to enable showing of errors.
     
    13641452         * @see wpdb::hide_errors()
    13651453         *
    13661454         * @param bool $show Whether to show or hide errors
     1455         *
    13671456         * @return bool Old value for showing errors.
    13681457         */
    13691458        public function show_errors( $show = true ) {
    1370                 $errors = $this->show_errors;
     1459                $errors            = $this->show_errors;
    13711460                $this->show_errors = $show;
     1461
    13721462                return $errors;
    13731463        }
    13741464
     
    13831473         * @return bool Whether showing of errors was active
    13841474         */
    13851475        public function hide_errors() {
    1386                 $show = $this->show_errors;
     1476                $show              = $this->show_errors;
    13871477                $this->show_errors = false;
     1478
    13881479                return $show;
    13891480        }
    13901481
     
    13961487         *
    13971488         * @since 2.5.0
    13981489         * @see wpdb::hide_errors()
     1490         *
    13991491         * @param bool $suppress Optional. New value. Defaults to true.
     1492         *
    14001493         * @return bool Old value
    14011494         */
    14021495        public function suppress_errors( $suppress = true ) {
    1403                 $errors = $this->suppress_errors;
     1496                $errors                = $this->suppress_errors;
    14041497                $this->suppress_errors = (bool) $suppress;
     1498
    14051499                return $errors;
    14061500        }
    14071501
     
    14111505         * @since 0.71
    14121506         */
    14131507        public function flush() {
    1414                 $this->last_result = array();
    1415                 $this->col_info    = null;
    1416                 $this->last_query  = null;
     1508                $this->last_result   = array();
     1509                $this->col_info      = null;
     1510                $this->last_query    = null;
    14171511                $this->rows_affected = $this->num_rows = 0;
    1418                 $this->last_error  = '';
     1512                $this->last_error    = '';
    14191513
    14201514                if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
    14211515                        mysqli_free_result( $this->result );
     
    14221516                        $this->result = null;
    14231517
    14241518                        // Sanity check before using the handle
    1425                         if ( empty( $this->dbh ) || !( $this->dbh instanceof mysqli ) ) {
     1519                        if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) {
    14261520                                return;
    14271521                        }
    14281522
     
    14451539         * @since 3.9.0 $allow_bail parameter added.
    14461540         *
    14471541         * @param bool $allow_bail Optional. Allows the function to bail. Default true.
     1542         *
    14481543         * @return bool True with a successful connection, false on failure.
    14491544         */
    14501545        public function db_connect( $allow_bail = true ) {
     
    14541549                 * Deprecated in 3.9+ when using MySQLi. No equivalent
    14551550                 * $new_link parameter exists for mysqli_* functions.
    14561551                 */
    1457                 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
     1552                $new_link     = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
    14581553                $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
    14591554
    14601555                if ( $this->use_mysqli ) {
     
    14621557
    14631558                        // mysqli_real_connect doesn't support the host param including a port or socket
    14641559                        // like mysql_connect does. This duplicates how mysql_connect detects a port and/or socket file.
    1465                         $port = null;
    1466                         $socket = null;
    1467                         $host = $this->dbhost;
     1560                        $port           = null;
     1561                        $socket         = null;
     1562                        $host           = $this->dbhost;
    14681563                        $port_or_socket = strstr( $host, ':' );
    14691564                        if ( ! empty( $port_or_socket ) ) {
    1470                                 $host = substr( $host, 0, strpos( $host, ':' ) );
     1565                                $host           = substr( $host, 0, strpos( $host, ':' ) );
    14711566                                $port_or_socket = substr( $port_or_socket, 1 );
    14721567                                if ( 0 !== strpos( $port_or_socket, '/' ) ) {
    1473                                         $port = intval( $port_or_socket );
     1568                                        $port         = intval( $port_or_socket );
    14741569                                        $maybe_socket = strstr( $port_or_socket, ':' );
    14751570                                        if ( ! empty( $maybe_socket ) ) {
    14761571                                                $socket = substr( $maybe_socket, 1 );
     
    15061601
    15071602                                if ( $attempt_fallback ) {
    15081603                                        $this->use_mysqli = false;
     1604
    15091605                                        return $this->db_connect( $allow_bail );
    15101606                                }
    15111607                        }
     
    15301626
    15311627                        $message .= '<p>' . sprintf(
    15321628                                /* translators: 1: wp-config.php. 2: database host */
    1533                                 __( 'This either means that the username and password information in your %1$s file is incorrect or we can&#8217;t contact the database server at %2$s. This could mean your host&#8217;s database server is down.' ),
    1534                                 '<code>wp-config.php</code>',
    1535                                 '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
    1536                         ) . "</p>\n";
     1629                                        __( 'This either means that the username and password information in your %1$s file is incorrect or we can&#8217;t contact the database server at %2$s. This could mean your host&#8217;s database server is down.' ),
     1630                                        '<code>wp-config.php</code>',
     1631                                        '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
     1632                                ) . "</p>\n";
    15371633
    15381634                        $message .= "<ul>\n";
    15391635                        $message .= '<li>' . __( 'Are you sure you have the correct username and password?' ) . "</li>\n";
     
    15431639
    15441640                        $message .= '<p>' . sprintf(
    15451641                                /* translators: %s: support forums URL */
    1546                                 __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
    1547                                 __( 'https://wordpress.org/support/' )
    1548                         ) . "</p>\n";
     1642                                        __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
     1643                                        __( 'https://wordpress.org/support/' )
     1644                                ) . "</p>\n";
    15491645
    15501646                        $this->bail( $message, 'db_connect_fail' );
    15511647
     
    15811677         * @since 3.9.0
    15821678         *
    15831679         * @param bool $allow_bail Optional. Allows the function to bail. Default true.
     1680         *
    15841681         * @return bool|void True if the connection is up.
    15851682         */
    15861683        public function check_connection( $allow_bail = true ) {
     
    16021699                        error_reporting( $error_reporting & ~E_WARNING );
    16031700                }
    16041701
    1605                 for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) {
     1702                for ( $tries = 1; $tries <= $this->reconnect_retries; $tries ++ ) {
    16061703                        // On the last try, re-enable warnings. We want to see a single instance of the
    16071704                        // "unable to connect" message on the bail() screen, if it appears.
    16081705                        if ( $this->reconnect_retries === $tries && WP_DEBUG ) {
     
    16361733
    16371734                $message .= '<p>' . sprintf(
    16381735                        /* translators: %s: database host */
    1639                         __( 'This means that we lost contact with the database server at %s. This could mean your host&#8217;s database server is down.' ),
    1640                         '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
    1641                 ) . "</p>\n";
     1736                                __( 'This means that we lost contact with the database server at %s. This could mean your host&#8217;s database server is down.' ),
     1737                                '<code>' . htmlspecialchars( $this->dbhost, ENT_QUOTES ) . '</code>'
     1738                        ) . "</p>\n";
    16421739
    16431740                $message .= "<ul>\n";
    16441741                $message .= '<li>' . __( 'Are you sure that the database server is running?' ) . "</li>\n";
     
    16471744
    16481745                $message .= '<p>' . sprintf(
    16491746                        /* translators: %s: support forums URL */
    1650                         __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
    1651                         __( 'https://wordpress.org/support/' )
    1652                 ) . "</p>\n";
     1747                                __( 'If you&#8217;re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="%s">WordPress Support Forums</a>.' ),
     1748                                __( 'https://wordpress.org/support/' )
     1749                        ) . "</p>\n";
    16531750
    16541751                // We weren't able to reconnect, so we better bail.
    16551752                $this->bail( $message, 'db_connect_fail' );
     
    16661763         * @since 0.71
    16671764         *
    16681765         * @param string $query Database query
     1766         *
    16691767         * @return int|false Number of rows affected/selected or false on error
    16701768         */
    16711769        public function query( $query ) {
    16721770                if ( ! $this->ready ) {
    16731771                        $this->check_current_query = true;
     1772
    16741773                        return false;
    16751774                }
    16761775
     
    16991798                        $this->flush();
    17001799                        if ( $stripped_query !== $query ) {
    17011800                                $this->insert_id = 0;
     1801
    17021802                                return false;
    17031803                        }
    17041804                }
     
    17351835                                $this->_do_query( $query );
    17361836                        } else {
    17371837                                $this->insert_id = 0;
     1838
    17381839                                return false;
    17391840                        }
    17401841                }
     
    17421843                // If there is an error then take note of it.
    17431844                if ( $this->use_mysqli ) {
    17441845                        if ( $this->dbh instanceof mysqli ) {
    1745                                 $this->last_error = mysqli_error( $this->dbh );
     1846                                $this->last_error = $this->get_error();
    17461847                        } else {
    17471848                                $this->last_error = __( 'Unable to retrieve the error message from MySQL' );
    17481849                        }
     
    17561857
    17571858                if ( $this->last_error ) {
    17581859                        // Clear insert_id on a subsequent failed insert.
    1759                         if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) )
     1860                        if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
    17601861                                $this->insert_id = 0;
     1862                        }
    17611863
    17621864                        $this->print_error();
     1865
    17631866                        return false;
    17641867                }
    17651868
     
    17851888                        $num_rows = 0;
    17861889                        if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
    17871890                                while ( $row = mysqli_fetch_object( $this->result ) ) {
    1788                                         $this->last_result[$num_rows] = $row;
    1789                                         $num_rows++;
     1891                                        $this->last_result[ $num_rows ] = $row;
     1892                                        $num_rows ++;
    17901893                                }
    17911894                        } elseif ( is_resource( $this->result ) ) {
    17921895                                while ( $row = mysql_fetch_object( $this->result ) ) {
    1793                                         $this->last_result[$num_rows] = $row;
    1794                                         $num_rows++;
     1896                                        $this->last_result[ $num_rows ] = $row;
     1897                                        $num_rows ++;
    17951898                                }
    17961899                        }
    17971900
     
    18231926                } elseif ( ! empty( $this->dbh ) ) {
    18241927                        $this->result = mysql_query( $query, $this->dbh );
    18251928                }
    1826                 $this->num_queries++;
     1929                $this->num_queries ++;
    18271930
    18281931                if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) {
    18291932                        $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
     
    18411944         * @see wpdb::$field_types
    18421945         * @see wp_set_wpdb_vars()
    18431946         *
    1844          * @param string       $table Table name
    1845          * @param array        $data  Data to insert (in column => value pairs).
     1947         * @param string $table Table name
     1948         * @param array $data Data to insert (in column => value pairs).
    18461949         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    18471950         *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
    18481951         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
     
    18491952         *                             If string, that format will be used for all of the values in $data.
    18501953         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    18511954         *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     1955         *
    18521956         * @return int|false The number of rows inserted, or false on error.
    18531957         */
    18541958        public function insert( $table, $data, $format = null ) {
     
    18661970         * @see wpdb::$field_types
    18671971         * @see wp_set_wpdb_vars()
    18681972         *
    1869          * @param string       $table Table name
    1870          * @param array        $data  Data to insert (in column => value pairs).
     1973         * @param string $table Table name
     1974         * @param array $data Data to insert (in column => value pairs).
    18711975         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    18721976         *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
    18731977         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
     
    18741978         *                             If string, that format will be used for all of the values in $data.
    18751979         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    18761980         *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     1981         *
    18771982         * @return int|false The number of rows affected, or false on error.
    18781983         */
    18791984        public function replace( $table, $data, $format = null ) {
     
    18901995         * @see wpdb::$field_types
    18911996         * @see wp_set_wpdb_vars()
    18921997         *
    1893          * @param string       $table Table name
    1894          * @param array        $data  Data to insert (in column => value pairs).
     1998         * @param string $table Table name
     1999         * @param array $data Data to insert (in column => value pairs).
    18952000         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    18962001         *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
    18972002         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
     
    18982003         *                             If string, that format will be used for all of the values in $data.
    18992004         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    19002005         *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
    1901          * @param string $type         Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
     2006         * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
     2007         *
    19022008         * @return int|false The number of rows affected, or false on error.
    19032009         */
    19042010        function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {
     
    19302036                $sql = "$type INTO `$table` ($fields) VALUES ($formats)";
    19312037
    19322038                $this->check_current_query = false;
     2039
    19332040                return $this->query( $this->prepare( $sql, $values ) );
    19342041        }
    19352042
     
    19442051         * @see wpdb::$field_types
    19452052         * @see wp_set_wpdb_vars()
    19462053         *
    1947          * @param string       $table        Table name
    1948          * @param array        $data        Data to update (in column => value pairs).
     2054         * @param string $table Table name
     2055         * @param array $data Data to update (in column => value pairs).
    19492056         *                                   Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    19502057         *                                   Sending a null value will cause the column to be set to NULL - the corresponding
    19512058         *                                   format is ignored in this case.
    1952          * @param array        $where        A named array of WHERE clauses (in column => value pairs).
     2059         * @param array $where A named array of WHERE clauses (in column => value pairs).
    19532060         *                                   Multiple clauses will be joined with ANDs.
    19542061         *                                   Both $where columns and $where values should be "raw".
    19552062         *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
    1956          * @param array|string $format       Optional. An array of formats to be mapped to each of the values in $data.
     2063         * @param array|string $format Optional. An array of formats to be mapped to each of the values in $data.
    19572064         *                                   If string, that format will be used for all of the values in $data.
    19582065         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    19592066         *                                   If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     
    19612068         *                                   If string, that format will be used for all of the items in $where.
    19622069         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    19632070         *                                   If omitted, all values in $where will be treated as strings.
     2071         *
    19642072         * @return int|false The number of rows updated, or false on error.
    19652073         */
    19662074        public function update( $table, $data, $where, $format = null, $where_format = null ) {
     
    19942102                        }
    19952103
    19962104                        $conditions[] = "`$field` = " . $value['format'];
    1997                         $values[] = $value['value'];
     2105                        $values[]     = $value['value'];
    19982106                }
    19992107
    2000                 $fields = implode( ', ', $fields );
     2108                $fields     = implode( ', ', $fields );
    20012109                $conditions = implode( ' AND ', $conditions );
    20022110
    20032111                $sql = "UPDATE `$table` SET $fields WHERE $conditions";
    20042112
    20052113                $this->check_current_query = false;
     2114
    20062115                return $this->query( $this->prepare( $sql, $values ) );
    20072116        }
    20082117
     
    20172126         * @see wpdb::$field_types
    20182127         * @see wp_set_wpdb_vars()
    20192128         *
    2020          * @param string       $table        Table name
    2021          * @param array        $where        A named array of WHERE clauses (in column => value pairs).
     2129         * @param string $table Table name
     2130         * @param array $where A named array of WHERE clauses (in column => value pairs).
    20222131         *                                   Multiple clauses will be joined with ANDs.
    20232132         *                                   Both $where columns and $where values should be "raw".
    20242133         *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
     
    20262135         *                                   If string, that format will be used for all of the items in $where.
    20272136         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    20282137         *                                   If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
     2138         *
    20292139         * @return int|false The number of rows updated, or false on error.
    20302140         */
    20312141        public function delete( $table, $where, $where_format = null ) {
     
    20462156                        }
    20472157
    20482158                        $conditions[] = "`$field` = " . $value['format'];
    2049                         $values[] = $value['value'];
     2159                        $values[]     = $value['value'];
    20502160                }
    20512161
    20522162                $conditions = implode( ' AND ', $conditions );
     
    20542164                $sql = "DELETE FROM `$table` WHERE $conditions";
    20552165
    20562166                $this->check_current_query = false;
     2167
    20572168                return $this->query( $this->prepare( $sql, $values ) );
    20582169        }
    20592170
     
    20682179         *
    20692180         * @since 4.2.0
    20702181         *
    2071          * @param string $table  Table name.
    2072          * @param array  $data   Field/value pair.
    2073          * @param mixed  $format Format for each field.
     2182         * @param string $table Table name.
     2183         * @param array $data Field/value pair.
     2184         * @param mixed $format Format for each field.
     2185         *
    20742186         * @return array|false Returns an array of fields that contain paired values
    20752187         *                    and formats. Returns false for invalid values.
    20762188         */
     
    21042216         *
    21052217         * @since 4.2.0
    21062218         *
    2107          * @param array $data   Array of fields to values.
     2219         * @param array $data Array of fields to values.
    21082220         * @param mixed $format Formats to be mapped to the values in $data.
     2221         *
    21092222         * @return array Array, keyed by field names with values being an array
    21102223         *               of 'value' and 'format' keys.
    21112224         */
     
    21392252         *
    21402253         * @since 4.2.0
    21412254         *
    2142          * @param array  $data As it comes from the wpdb::process_field_formats() method.
     2255         * @param array $data As it comes from the wpdb::process_field_formats() method.
    21432256         * @param string $table Table name.
     2257         *
    21442258         * @return array|false The same array as $data with additional 'charset' keys.
    21452259         */
    21462260        protected function process_field_charsets( $data, $table ) {
     
    21692283         *
    21702284         * @since 4.2.1
    21712285         *
    2172          * @param array  $data As it comes from the wpdb::process_field_charsets() method.
     2286         * @param array $data As it comes from the wpdb::process_field_charsets() method.
    21732287         * @param string $table Table name.
     2288         *
    21742289         * @return array|false The same array as $data with additional 'length' keys, or false if
    21752290         *                     any of the values were too long for their corresponding field.
    21762291         */
     
    22052320         * @since 0.71
    22062321         *
    22072322         * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query.
    2208          * @param int         $x     Optional. Column of value to return. Indexed from 0.
    2209          * @param int         $y     Optional. Row of value to return. Indexed from 0.
     2323         * @param int $x Optional. Column of value to return. Indexed from 0.
     2324         * @param int $y Optional. Row of value to return. Indexed from 0.
     2325         *
    22102326         * @return string|null Database query result (as string), or null on failure
    22112327         */
    22122328        public function get_var( $query = null, $x = 0, $y = 0 ) {
     
    22212337                }
    22222338
    22232339                // Extract var out of cached results based x,y vals
    2224                 if ( !empty( $this->last_result[$y] ) ) {
    2225                         $values = array_values( get_object_vars( $this->last_result[$y] ) );
     2340                if ( ! empty( $this->last_result[ $y ] ) ) {
     2341                        $values = array_values( get_object_vars( $this->last_result[ $y ] ) );
    22262342                }
    22272343
    22282344                // If there is a value return it else return null
    2229                 return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null;
     2345                return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ] : null;
    22302346        }
    22312347
    22322348        /**
     
    22362352         *
    22372353         * @since 0.71
    22382354         *
    2239          * @param string|null $query  SQL query.
    2240          * @param string      $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
     2355         * @param string|null $query SQL query.
     2356         * @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
    22412357         *                            an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT.
    2242          * @param int         $y      Optional. Row to return. Indexed from 0.
     2358         * @param int $y Optional. Row to return. Indexed from 0.
     2359         *
    22432360         * @return array|object|null|void Database query result in format specified by $output or null on failure
    22442361         */
    22452362        public function get_row( $query = null, $output = OBJECT, $y = 0 ) {
     
    22552372                        return null;
    22562373                }
    22572374
    2258                 if ( !isset( $this->last_result[$y] ) )
     2375                if ( ! isset( $this->last_result[ $y ] ) ) {
    22592376                        return null;
     2377                }
    22602378
    22612379                if ( $output == OBJECT ) {
    2262                         return $this->last_result[$y] ? $this->last_result[$y] : null;
     2380                        return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
    22632381                } elseif ( $output == ARRAY_A ) {
    2264                         return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null;
     2382                        return $this->last_result[ $y ] ? get_object_vars( $this->last_result[ $y ] ) : null;
    22652383                } elseif ( $output == ARRAY_N ) {
    2266                         return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;
     2384                        return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null;
    22672385                } elseif ( strtoupper( $output ) === OBJECT ) {
    22682386                        // Back compat for OBJECT being previously case insensitive.
    2269                         return $this->last_result[$y] ? $this->last_result[$y] : null;
     2387                        return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
    22702388                } else {
    22712389                        $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" );
    22722390                }
     
    22822400         * @since 0.71
    22832401         *
    22842402         * @param string|null $query Optional. SQL query. Defaults to previous query.
    2285          * @param int         $x     Optional. Column to return. Indexed from 0.
     2403         * @param int $x Optional. Column to return. Indexed from 0.
     2404         *
    22862405         * @return array Database query result. Array indexed from 0 by SQL result row number.
    22872406         */
    2288         public function get_col( $query = null , $x = 0 ) {
     2407        public function get_col( $query = null, $x = 0 ) {
    22892408                if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
    22902409                        $this->check_current_query = false;
    22912410                }
     
    22962415
    22972416                $new_array = array();
    22982417                // Extract the column values
    2299                 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
    2300                         $new_array[$i] = $this->get_var( null, $x, $i );
     2418                for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i ++ ) {
     2419                        $new_array[ $i ] = $this->get_var( null, $x, $i );
    23012420                }
     2421
    23022422                return $new_array;
    23032423        }
    23042424
     
    23092429         *
    23102430         * @since 0.71
    23112431         *
    2312          * @param string $query  SQL query.
     2432         * @param string $query SQL query.
    23132433         * @param string $output Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.
    23142434         *                       With one of the first three, return an array of rows indexed from 0 by SQL result row number.
    23152435         *                       Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.
    23162436         *                       With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value.
    23172437         *                       Duplicate keys are discarded.
     2438         *
    23182439         * @return array|object|null Database query results
    23192440         */
    23202441        public function get_results( $query = null, $output = OBJECT ) {
     
    23392460                        // (Duplicates are discarded)
    23402461                        foreach ( $this->last_result as $row ) {
    23412462                                $var_by_ref = get_object_vars( $row );
    2342                                 $key = array_shift( $var_by_ref );
    2343                                 if ( ! isset( $new_array[ $key ] ) )
     2463                                $key        = array_shift( $var_by_ref );
     2464                                if ( ! isset( $new_array[ $key ] ) ) {
    23442465                                        $new_array[ $key ] = $row;
     2466                                }
    23452467                        }
     2468
    23462469                        return $new_array;
    23472470                } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
    23482471                        // Return an integer-keyed array of...
     
    23572480                                        }
    23582481                                }
    23592482                        }
     2483
    23602484                        return $new_array;
    23612485                } elseif ( strtoupper( $output ) === OBJECT ) {
    23622486                        // Back compat for OBJECT being previously case insensitive.
    23632487                        return $this->last_result;
    23642488                }
     2489
    23652490                return null;
    23662491        }
    23672492
     
    23712496         * @since 4.2.0
    23722497         *
    23732498         * @param string $table Table name.
     2499         *
    23742500         * @return string|WP_Error Table character set, WP_Error object if it couldn't be found.
    23752501         */
    23762502        protected function get_table_charset( $table ) {
     
    23852511                 * @since 4.2.0
    23862512                 *
    23872513                 * @param string $charset The character set to use. Default null.
    2388                  * @param string $table   The name of the table being checked.
     2514                 * @param string $table The name of the table being checked.
    23892515                 */
    23902516                $charset = apply_filters( 'pre_get_table_charset', null, $table );
    23912517                if ( null !== $charset ) {
     
    23992525                $charsets = $columns = array();
    24002526
    24012527                $table_parts = explode( '.', $table );
    2402                 $table = '`' . implode( '`.`', $table_parts ) . '`';
    2403                 $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
     2528                $table       = '`' . implode( '`.`', $table_parts ) . '`';
     2529                $results     = $this->get_results( "SHOW FULL COLUMNS FROM $table" );
    24042530                if ( ! $results ) {
    24052531                        return new WP_Error( 'wpdb_get_table_charset_failure' );
    24062532                }
     
    24262552                        list( $type ) = explode( '(', $column->Type );
    24272553
    24282554                        // A binary/blob means the whole query gets treated like this.
    2429                         if ( in_array( strtoupper( $type ), array( 'BINARY', 'VARBINARY', 'TINYBLOB', 'MEDIUMBLOB', 'BLOB', 'LONGBLOB' ) ) ) {
     2555                        if ( in_array( strtoupper( $type ), array(
     2556                                'BINARY',
     2557                                'VARBINARY',
     2558                                'TINYBLOB',
     2559                                'MEDIUMBLOB',
     2560                                'BLOB',
     2561                                'LONGBLOB'
     2562                        ) ) ) {
    24302563                                $this->table_charset[ $tablekey ] = 'binary';
     2564
    24312565                                return 'binary';
    24322566                        }
    24332567                }
     
    24622596                }
    24632597
    24642598                $this->table_charset[ $tablekey ] = $charset;
     2599
    24652600                return $charset;
    24662601        }
    24672602
     
    24702605         *
    24712606         * @since 4.2.0
    24722607         *
    2473          * @param string $table  Table name.
     2608         * @param string $table Table name.
    24742609         * @param string $column Column name.
     2610         *
    24752611         * @return string|false|WP_Error Column character set as a string. False if the column has no
    24762612         *                               character set. WP_Error object if there was an error.
    24772613         */
    24782614        public function get_col_charset( $table, $column ) {
    2479                 $tablekey = strtolower( $table );
     2615                $tablekey  = strtolower( $table );
    24802616                $columnkey = strtolower( $column );
    24812617
    24822618                /**
     
    24882624                 * @since 4.2.0
    24892625                 *
    24902626                 * @param string $charset The character set to use. Default null.
    2491                  * @param string $table   The name of the table being checked.
    2492                  * @param string $column  The name of the column being checked.
     2627                 * @param string $table The name of the table being checked.
     2628                 * @param string $column The name of the column being checked.
    24932629                 */
    24942630                $charset = apply_filters( 'pre_get_col_charset', null, $table, $column );
    24952631                if ( null !== $charset ) {
     
    25252661                }
    25262662
    25272663                list( $charset ) = explode( '_', $this->col_meta[ $tablekey ][ $columnkey ]->Collation );
     2664
    25282665                return $charset;
    25292666        }
    25302667
     
    25342671         *
    25352672         * @since 4.2.1
    25362673         *
    2537          * @param string $table  Table name.
     2674         * @param string $table Table name.
    25382675         * @param string $column Column name.
     2676         *
    25392677         * @return array|false|WP_Error array( 'length' => (int), 'type' => 'byte' | 'char' )
    25402678         *                              false if the column has no length (for example, numeric column)
    25412679         *                              WP_Error object if there was an error.
    25422680         */
    25432681        public function get_col_length( $table, $column ) {
    2544                 $tablekey = strtolower( $table );
     2682                $tablekey  = strtolower( $table );
    25452683                $columnkey = strtolower( $column );
    25462684
    25472685                // Skip this entirely if this isn't a MySQL database.
     
    25702708                        $length = false;
    25712709                }
    25722710
    2573                 switch( $type ) {
     2711                switch ( $type ) {
    25742712                        case 'char':
    25752713                        case 'varchar':
    25762714                                return array(
     
    26272765         * @since 4.2.0
    26282766         *
    26292767         * @param string $string String to check.
     2768         *
    26302769         * @return bool True if ASCII, false if not.
    26312770         */
    26322771        protected function check_ascii( $string ) {
     
    26472786         * @since 4.2.0
    26482787         *
    26492788         * @param string $query The query to check.
     2789         *
    26502790         * @return bool True if the collation is safe, false if it isn't.
    26512791         */
    26522792        protected function check_safe_collation( $query ) {
     
    26712811                }
    26722812
    26732813                $this->checking_collation = true;
    2674                 $collation = $this->get_table_charset( $table );
     2814                $collation                = $this->get_table_charset( $table );
    26752815                $this->checking_collation = false;
    26762816
    26772817                // Tables with no collation, or latin1 only, don't need extra checking.
     
    26902830                                continue;
    26912831                        }
    26922832
    2693                         if ( ! in_array( $col->Collation, array( 'utf8_general_ci', 'utf8_bin', 'utf8mb4_general_ci', 'utf8mb4_bin' ), true ) ) {
     2833                        if ( ! in_array( $col->Collation, array(
     2834                                'utf8_general_ci',
     2835                                'utf8_bin',
     2836                                'utf8mb4_general_ci',
     2837                                'utf8mb4_bin'
     2838                        ), true ) ) {
    26942839                                return false;
    26952840                        }
    26962841                }
     
    27062851         * @param array $data Array of value arrays. Each value array has the keys
    27072852         *                    'value' and 'charset'. An optional 'ascii' key can be
    27082853         *                    set to false to avoid redundant ASCII checks.
     2854         *
    27092855         * @return array|WP_Error The $data parameter, with invalid characters removed from
    27102856         *                        each value. This works as a passthrough: any additional keys
    27112857         *                        such as 'field' are retained in each value array. If we cannot
     
    27182864                        $charset = $value['charset'];
    27192865
    27202866                        if ( is_array( $value['length'] ) ) {
    2721                                 $length = $value['length']['length'];
     2867                                $length                  = $value['length']['length'];
    27222868                                $truncate_by_byte_length = 'byte' === $value['length']['type'];
    27232869                        } else {
    27242870                                $length = false;
     
    27422888                        if (
    27432889                                // latin1 can store any byte sequence
    27442890                                'latin1' === $charset
    2745                         ||
     2891                                ||
    27462892                                // ASCII is always OK.
    27472893                                ( ! isset( $value['ascii'] ) && $this->check_ascii( $value['value'] ) )
    27482894                        ) {
    27492895                                $truncate_by_byte_length = true;
    2750                                 $needs_validation = false;
     2896                                $needs_validation        = false;
    27512897                        }
    27522898
    27532899                        if ( $truncate_by_byte_length ) {
     
    27812927                                        ';
    27822928                                }
    27832929
    2784                                 $regex .= '){1,40}                          # ...one or more times
     2930                                $regex          .= '){1,40}                          # ...one or more times
    27852931                                        )
    27862932                                        | .                                  # anything else
    27872933                                        /x';
     
    28222968                                        }
    28232969
    28242970                                        if ( is_array( $value['length'] ) ) {
    2825                                                 $length = sprintf( '%.0f', $value['length']['length'] );
     2971                                                $length          = sprintf( '%.0f', $value['length']['length'] );
    28262972                                                $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] );
    28272973                                        } else if ( 'binary' !== $charset ) {
    28282974                                                // If we don't have a length, there's no need to convert binary - it will always return the same result.
     
    28432989                        }
    28442990
    28452991                        $this->check_current_query = false;
    2846                         $row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A );
     2992                        $row                       = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A );
    28472993                        if ( ! $row ) {
    28482994                                return new WP_Error( 'wpdb_strip_invalid_text_failure' );
    28492995                        }
     
    28643010         * @since 4.2.0
    28653011         *
    28663012         * @param string $query Query to convert.
     3013         *
    28673014         * @return string|WP_Error The converted query, or a WP_Error object if the conversion fails.
    28683015         */
    28693016        protected function strip_invalid_text_from_query( $query ) {
     
    29083055         *
    29093056         * @since 4.2.0
    29103057         *
    2911          * @param string $table  Table name.
     3058         * @param string $table Table name.
    29123059         * @param string $column Column name.
    2913          * @param string $value  The text to check.
     3060         * @param string $value The text to check.
     3061         *
    29143062         * @return string|WP_Error The converted string, or a WP_Error object if the conversion fails.
    29153063         */
    29163064        public function strip_invalid_text_for_column( $table, $column, $value ) {
     
    29493097         * @since 4.2.0
    29503098         *
    29513099         * @param string $query The query to search.
     3100         *
    29523101         * @return string|false $table The table name found, or false if a table couldn't be found.
    29533102         */
    29543103        protected function get_table_from_query( $query ) {
     
    29633112
    29643113                // Quickly match most common queries.
    29653114                if ( preg_match( '/^\s*(?:'
    2966                                 . 'SELECT.*?\s+FROM'
    2967                                 . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
    2968                                 . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
    2969                                 . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
    2970                                 . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?'
    2971                                 . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
     3115                                 . 'SELECT.*?\s+FROM'
     3116                                 . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
     3117                                 . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
     3118                                 . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
     3119                                 . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?'
     3120                                 . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) {
    29723121                        return str_replace( '`', '', $maybe[1] );
    29733122                }
    29743123
     
    29883137
    29893138                // Big pattern for the rest of the table-related queries.
    29903139                if ( preg_match( '/^\s*(?:'
    2991                                 . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
    2992                                 . '|DESCRIBE|DESC|EXPLAIN|HANDLER'
    2993                                 . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?'
    2994                                 . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|REPAIR).*\s+TABLE'
    2995                                 . '|TRUNCATE(?:\s+TABLE)?'
    2996                                 . '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?'
    2997                                 . '|ALTER(?:\s+IGNORE)?\s+TABLE'
    2998                                 . '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?'
    2999                                 . '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON'
    3000                                 . '|DROP\s+INDEX.*\s+ON'
    3001                                 . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
    3002                                 . '|(?:GRANT|REVOKE).*ON\s+TABLE'
    3003                                 . '|SHOW\s+(?:.*FROM|.*TABLE)'
    3004                                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
     3140                                 . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
     3141                                 . '|DESCRIBE|DESC|EXPLAIN|HANDLER'
     3142                                 . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?'
     3143                                 . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|REPAIR).*\s+TABLE'
     3144                                 . '|TRUNCATE(?:\s+TABLE)?'
     3145                                 . '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?'
     3146                                 . '|ALTER(?:\s+IGNORE)?\s+TABLE'
     3147                                 . '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?'
     3148                                 . '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON'
     3149                                 . '|DROP\s+INDEX.*\s+ON'
     3150                                 . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
     3151                                 . '|(?:GRANT|REVOKE).*ON\s+TABLE'
     3152                                 . '|SHOW\s+(?:.*FROM|.*TABLE)'
     3153                                 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) {
    30053154                        return str_replace( '`', '', $maybe[1] );
    30063155                }
    30073156
     
    30153164         *
    30163165         */
    30173166        protected function load_col_info() {
    3018                 if ( $this->col_info )
     3167                if ( $this->col_info ) {
    30193168                        return;
     3169                }
    30203170
    30213171                if ( $this->use_mysqli ) {
    30223172                        $num_fields = mysqli_num_fields( $this->result );
    3023                         for ( $i = 0; $i < $num_fields; $i++ ) {
     3173                        for ( $i = 0; $i < $num_fields; $i ++ ) {
    30243174                                $this->col_info[ $i ] = mysqli_fetch_field( $this->result );
    30253175                        }
    30263176                } else {
    30273177                        $num_fields = mysql_num_fields( $this->result );
    3028                         for ( $i = 0; $i < $num_fields; $i++ ) {
     3178                        for ( $i = 0; $i < $num_fields; $i ++ ) {
    30293179                                $this->col_info[ $i ] = mysql_fetch_field( $this->result, $i );
    30303180                        }
    30313181                }
     
    30363186         *
    30373187         * @since 0.71
    30383188         *
    3039          * @param string $info_type  Optional. Type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
    3040          * @param int    $col_offset Optional. 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type
     3189         * @param string $info_type Optional. Type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
     3190         * @param int $col_offset Optional. 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type
     3191         *
    30413192         * @return mixed Column Results
    30423193         */
    3043         public function get_col_info( $info_type = 'name', $col_offset = -1 ) {
     3194        public function get_col_info( $info_type = 'name', $col_offset = - 1 ) {
    30443195                $this->load_col_info();
    30453196
    30463197                if ( $this->col_info ) {
    3047                         if ( $col_offset == -1 ) {
    3048                                 $i = 0;
     3198                        if ( $col_offset == - 1 ) {
     3199                                $i         = 0;
    30493200                                $new_array = array();
    30503201                                foreach ( (array) $this->col_info as $col ) {
    3051                                         $new_array[$i] = $col->{$info_type};
    3052                                         $i++;
     3202                                        $new_array[ $i ] = $col->{$info_type};
     3203                                        $i ++;
    30533204                                }
     3205
    30543206                                return $new_array;
    30553207                        } else {
    3056                                 return $this->col_info[$col_offset]->{$info_type};
     3208                                return $this->col_info[ $col_offset ]->{$info_type};
    30573209                        }
    30583210                }
    30593211        }
     
    30673219         */
    30683220        public function timer_start() {
    30693221                $this->time_start = microtime( true );
     3222
    30703223                return true;
    30713224        }
    30723225
     
    30883241         *
    30893242         * @since 1.5.0
    30903243         *
    3091          * @param string $message    The Error message
     3244         * @param string $message The Error message
    30923245         * @param string $error_code Optional. A Computer readable string to identify the error.
     3246         *
    30933247         * @return false|void
    30943248         */
    30953249        public function bail( $message, $error_code = '500' ) {
    3096                 if ( !$this->show_errors ) {
     3250                if ( ! $this->show_errors ) {
    30973251                        if ( class_exists( 'WP_Error', false ) ) {
    3098                                 $this->error = new WP_Error($error_code, $message);
     3252                                $this->error = new WP_Error( $error_code, $message );
    30993253                        } else {
    31003254                                $this->error = $message;
    31013255                        }
     3256
    31023257                        return false;
    31033258                }
    3104                 wp_die($message);
     3259                wp_die( $message );
    31053260        }
    31063261
    31073262
     
    31253280                }
    31263281
    31273282                if ( $closed ) {
    3128                         $this->dbh = null;
    3129                         $this->ready = false;
     3283                        $this->dbh           = null;
     3284                        $this->ready         = false;
    31303285                        $this->has_connected = false;
    31313286                }
    31323287
     
    31463301        public function check_database_version() {
    31473302                global $wp_version, $required_mysql_version;
    31483303                // Make sure the server has the required MySQL version
    3149                 if ( version_compare($this->db_version(), $required_mysql_version, '<') ) {
     3304                if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
    31503305                        /* translators: 1: WordPress version number, 2: Minimum required MySQL version number */
    3151                         return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ));
     3306                        return new WP_Error( 'database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) );
    31523307                }
    31533308        }
    31543309
     
    31663321         */
    31673322        public function supports_collation() {
    31683323                _deprecated_function( __FUNCTION__, '3.5.0', 'wpdb::has_cap( \'collation\' )' );
     3324
    31693325                return $this->has_cap( 'collation' );
    31703326        }
    31713327
     
    31793335        public function get_charset_collate() {
    31803336                $charset_collate = '';
    31813337
    3182                 if ( ! empty( $this->charset ) )
     3338                if ( ! empty( $this->charset ) ) {
    31833339                        $charset_collate = "DEFAULT CHARACTER SET $this->charset";
    3184                 if ( ! empty( $this->collate ) )
     3340                }
     3341                if ( ! empty( $this->collate ) ) {
    31853342                        $charset_collate .= " COLLATE $this->collate";
     3343                }
    31863344
    31873345                return $charset_collate;
    31883346        }
     
    31993357         * @param string $db_cap The feature to check for. Accepts 'collation',
    32003358         *                       'group_concat', 'subqueries', 'set_charset',
    32013359         *                       'utf8mb4', or 'utf8mb4_520'.
     3360         *
    32023361         * @return int|false Whether the database feature is supported, false otherwise.
    32033362         */
    32043363        public function has_cap( $db_cap ) {
     
    32273386                                 */
    32283387                                if ( false !== strpos( $client_version, 'mysqlnd' ) ) {
    32293388                                        $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version );
     3389
    32303390                                        return version_compare( $client_version, '5.0.9', '>=' );
    32313391                                } else {
    32323392                                        return version_compare( $client_version, '5.5.3', '>=' );
     
    32653425                } else {
    32663426                        $server_info = mysql_get_server_info( $this->dbh );
    32673427                }
     3428
    32683429                return preg_replace( '/[^0-9.].*/', '', $server_info );
    32693430        }
    32703431}