Make WordPress Core

Ticket #49477: 49477.diff

File 49477.diff, 53.4 KB (added by theMikeD, 6 years ago)
  • src/wp-includes/wp-db.php

     
    11<?php
    22/**
    3  * WordPress DB Class
     3 * WordPress database access abstraction class
    44 *
    55 * Original code from {@link http://php.justinvincent.com Justin Vincent (justin@visunet.ie)}
    66 *
     
    3737define( 'ARRAY_N', 'ARRAY_N' );
    3838
    3939/**
    40  * WordPress Database Access Abstraction Object
     40 * WordPress database access abstraction class
    4141 *
    42  * It is possible to replace this class with your own
    43  * by setting the $wpdb global variable in wp-content/db.php
    44  * file to your class. The wpdb class will still be included,
    45  * so you can extend it or simply use your own.
     42 * This class is used to interact with a database without needing to use raw SQL statements. By default, WordPress
     43 * uses this class to instantiate the global $wpdb object, providing access to the WordPress database.
    4644 *
    47  * @link https://codex.wordpress.org/Function_Reference/wpdb_Class
     45 * @link https://developer.wordpress.org/reference/classes/wpdb/
    4846 *
    4947 * @since 0.71
    5048 */
     
    5351        /**
    5452         * Whether to show SQL/DB errors.
    5553         *
    56          * Default behavior is to show errors if both WP_DEBUG and WP_DEBUG_DISPLAY
    57          * evaluated to true.
     54         * Default is to show errors if both WP_DEBUG and WP_DEBUG_DISPLAY evaluated to true.
    5855         *
    5956         * @since 0.71
    6057         * @var bool
     
    6259        var $show_errors = false;
    6360
    6461        /**
    65          * Whether to suppress errors during the DB bootstrapping.
     62         * Whether to suppress errors during the DB bootstrapping. Default is false.
    6663         *
    6764         * @since 2.5.0
    6865         * @var bool
     
    7067        var $suppress_errors = false;
    7168
    7269        /**
    73          * The last error during query.
     70         * The last error encountered during the last query.
    7471         *
    7572         * @since 2.5.0
    7673         * @var string
     
    7875        public $last_error = '';
    7976
    8077        /**
    81          * Amount of queries made
     78         * The number of queries made.
    8279         *
    8380         * @since 1.2.0
    8481         * @var int
     
    8683        public $num_queries = 0;
    8784
    8885        /**
    89          * Count of rows returned by previous query
     86         * Count of rows returned by the last query.
    9087         *
    9188         * @since 0.71
    9289         * @var int
     
    9491        public $num_rows = 0;
    9592
    9693        /**
    97          * Count of affected rows by previous query
     94         * Count of rows affected by the last query.
    9895         *
    9996         * @since 0.71
    10097         * @var int
     
    10299        var $rows_affected = 0;
    103100
    104101        /**
    105          * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).
     102         * The ID generated for an AUTO_INCREMENT column by the last query (usually INSERT).
    106103         *
    107104         * @since 0.71
    108105         * @var int
     
    110107        public $insert_id = 0;
    111108
    112109        /**
    113          * Last query made
     110         * The last query made.
    114111         *
    115112         * @since 0.71
    116113         * @var string
     
    118115        var $last_query;
    119116
    120117        /**
    121          * Results of the last query made
     118         * Results of the last query.
    122119         *
    123120         * @since 0.71
    124121         * @var array|null
     
    134131        protected $result;
    135132
    136133        /**
    137          * Cached column info, for sanity checking data before inserting
     134         * Cached column info, for sanity checking data before inserting.
    138135         *
    139136         * @since 4.2.0
    140137         * @var array
     
    142139        protected $col_meta = array();
    143140
    144141        /**
    145          * Calculated character sets on tables
     142         * Calculated character sets on tables.
    146143         *
    147144         * @since 4.2.0
    148145         * @var array
     
    150147        protected $table_charset = array();
    151148
    152149        /**
    153          * Whether text fields in the current query need to be sanity checked.
     150         * Whether text fields in the current query need to be sanity checked. Default is false.
    154151         *
    155152         * @since 4.2.0
    156153         * @var bool
     
    167164        private $checking_collation = false;
    168165
    169166        /**
    170          * Saved info on the table column
     167         * Saved info on the table column.
    171168         *
    172169         * @since 0.71
    173170         * @var array
     
    199196        var $queries;
    200197
    201198        /**
    202          * The number of times to retry reconnecting before dying.
     199         * The number of times to retry reconnecting before dying. Default is 5.
    203200         *
    204201         * @since 3.9.0
    205202         * @see wpdb::check_connection()
     
    210207        /**
    211208         * WordPress table prefix
    212209         *
    213          * You can set this to have multiple WordPress installations
    214          * in a single database. The second reason is for possible
    215          * security precautions.
     210         * You can set this to have multiple WordPress installations in a single database.
     211         * The second reason is for possible security precautions.
    216212         *
    217213         * @since 2.5.0
    218214         * @var string
     
    252248        public $siteid = 0;
    253249
    254250        /**
    255          * List of WordPress per-blog tables
     251         * List of WordPress per-blog tables.
    256252         *
    257253         * @since 2.5.0
    258254         * @see wpdb::tables()
     
    272268        );
    273269
    274270        /**
    275          * List of deprecated WordPress tables
     271         * List of deprecated WordPress tables.
    276272         *
    277          * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539
     273         * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539.
    278274         *
    279275         * @since 2.9.0
    280276         * @see wpdb::tables()
     
    283279        var $old_tables = array( 'categories', 'post2cat', 'link2cat' );
    284280
    285281        /**
    286          * List of WordPress global tables
     282         * List of WordPress global tables.
    287283         *
    288284         * @since 3.0.0
    289285         * @see wpdb::tables()
     
    292288        var $global_tables = array( 'users', 'usermeta' );
    293289
    294290        /**
    295          * List of Multisite global tables
     291         * List of Multisite global tables.
    296292         *
    297293         * @since 3.0.0
    298294         * @see wpdb::tables()
     
    309305        );
    310306
    311307        /**
    312          * WordPress Comments table
     308         * WordPress Comments table.
    313309         *
    314310         * @since 1.5.0
    315311         * @var string
     
    317313        public $comments;
    318314
    319315        /**
    320          * WordPress Comment Metadata table
     316         * WordPress Comment Metadata table.
    321317         *
    322318         * @since 2.9.0
    323319         * @var string
     
    325321        public $commentmeta;
    326322
    327323        /**
    328          * WordPress Links table
     324         * WordPress Links table.
    329325         *
    330326         * @since 1.5.0
    331327         * @var string
     
    333329        public $links;
    334330
    335331        /**
    336          * WordPress Options table
     332         * WordPress Options table.
    337333         *
    338334         * @since 1.5.0
    339335         * @var string
     
    341337        public $options;
    342338
    343339        /**
    344          * WordPress Post Metadata table
     340         * WordPress Post Metadata table.
    345341         *
    346342         * @since 1.5.0
    347343         * @var string
     
    349345        public $postmeta;
    350346
    351347        /**
    352          * WordPress Posts table
     348         * WordPress Posts table.
    353349         *
    354350         * @since 1.5.0
    355351         * @var string
     
    357353        public $posts;
    358354
    359355        /**
    360          * WordPress Terms table
     356         * WordPress Terms table.
    361357         *
    362358         * @since 2.3.0
    363359         * @var string
     
    365361        public $terms;
    366362
    367363        /**
    368          * WordPress Term Relationships table
     364         * WordPress Term Relationships table.
    369365         *
    370366         * @since 2.3.0
    371367         * @var string
     
    373369        public $term_relationships;
    374370
    375371        /**
    376          * WordPress Term Taxonomy table
     372         * WordPress Term Taxonomy table.
    377373         *
    378374         * @since 2.3.0
    379375         * @var string
     
    393389        //
    394390
    395391        /**
    396          * WordPress User Metadata table
     392         * WordPress User Metadata table.
    397393         *
    398394         * @since 2.3.0
    399395         * @var string
     
    401397        public $usermeta;
    402398
    403399        /**
    404          * WordPress Users table
     400         * WordPress Users table.
    405401         *
    406402         * @since 1.5.0
    407403         * @var string
     
    409405        public $users;
    410406
    411407        /**
    412          * Multisite Blogs table
     408         * Multisite Blogs table.
    413409         *
    414410         * @since 3.0.0
    415411         * @var string
     
    417413        public $blogs;
    418414
    419415        /**
    420          * Multisite Blog Metadata table
     416         * Multisite Blog Metadata table.
    421417         *
    422418         * @since 5.1.0
    423419         * @var string
     
    425421        public $blogmeta;
    426422
    427423        /**
    428          * Multisite Registration Log table
     424         * Multisite Registration Log table.
    429425         *
    430426         * @since 3.0.0
    431427         * @var string
     
    433429        public $registration_log;
    434430
    435431        /**
    436          * Multisite Signups table
     432         * Multisite Signups table.
    437433         *
    438434         * @since 3.0.0
    439435         * @var string
     
    441437        public $signups;
    442438
    443439        /**
    444          * Multisite Sites table
     440         * Multisite Sites table.
    445441         *
    446442         * @since 3.0.0
    447443         * @var string
     
    449445        public $site;
    450446
    451447        /**
    452          * Multisite Sitewide Terms table
     448         * Multisite Sitewide Terms table.
    453449         *
    454450         * @since 3.0.0
    455451         * @var string
     
    457453        public $sitecategories;
    458454
    459455        /**
    460          * Multisite Site Metadata table
     456         * Multisite Site Metadata table.
    461457         *
    462458         * @since 3.0.0
    463459         * @var string
     
    480476        public $field_types = array();
    481477
    482478        /**
    483          * Database table columns charset
     479         * Database table columns charset.
    484480         *
    485481         * @since 2.2.0
    486482         * @var string
     
    488484        public $charset;
    489485
    490486        /**
    491          * Database table columns collate
     487         * Database table columns collate.
    492488         *
    493489         * @since 2.2.0
    494490         * @var string
     
    496492        public $collate;
    497493
    498494        /**
    499          * Database Username
     495         * Database Username.
    500496         *
    501497         * @since 2.9.0
    502498         * @var string
     
    504500        protected $dbuser;
    505501
    506502        /**
    507          * Database Password
     503         * Database Password.
    508504         *
    509505         * @since 3.1.0
    510506         * @var string
     
    512508        protected $dbpassword;
    513509
    514510        /**
    515          * Database Name
     511         * Database Name.
    516512         *
    517513         * @since 3.1.0
    518514         * @var string
     
    520516        protected $dbname;
    521517
    522518        /**
    523          * Database Host
     519         * Database Host.
    524520         *
    525521         * @since 3.1.0
    526522         * @var string
     
    528524        protected $dbhost;
    529525
    530526        /**
    531          * Database Handle
     527         * Database Handle.
    532528         *
    533529         * @since 0.71
    534530         * @var string
     
    536532        protected $dbh;
    537533
    538534        /**
    539          * A textual description of the last query/get_row/get_var call
     535         * A textual description of the last query/get_row/get_var call.
    540536         *
    541537         * @since 3.0.0
    542538         * @var string
     
    572568        );
    573569
    574570        /**
    575          * Whether to use mysqli over mysql.
     571         * Whether to use mysqli over mysql. Default is false.
    576572         *
    577573         * @since 3.9.0
    578574         * @var bool
     
    580576        private $use_mysqli = false;
    581577
    582578        /**
    583          * Whether we've managed to successfully connect at some point
     579         * Whether we've managed to successfully connect at some point.
    584580         *
    585581         * @since 3.9.0
    586582         * @var bool
     
    588584        private $has_connected = false;
    589585
    590586        /**
    591          * Connects to the database server and selects a database
     587         * Connects to the database server and selects a database.
    592588         *
    593          * PHP5 style constructor for compatibility with PHP5. Does
    594          * the actual setting up of the class properties and connection
    595          * to the database.
     589         * PHP5 style constructor for compatibility with PHP5. Does the actual setting up of the class properties and
     590         * connection to the database.
    596591         *
    597592         * @link https://core.trac.wordpress.org/ticket/3354
    598593         * @since 2.0.8
    599594         *
    600          * @global string $wp_version The WordPress version string.
     595         * @global string $wp_version
    601596         *
    602          * @param string $dbuser     MySQL database user
    603          * @param string $dbpassword MySQL database password
    604          * @param string $dbname     MySQL database name
    605          * @param string $dbhost     MySQL database host
     597         * @param string $dbuser     MySQL database user.
     598         * @param string $dbpassword MySQL database password.
     599         * @param string $dbname     MySQL database name.
     600         * @param string $dbhost     MySQL database host.
    606601         */
    607602        public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
    608603                if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
     
    636631         *
    637632         * @since 3.5.0
    638633         *
    639          * @param string $name The private member to get, and optionally process
    640          * @return mixed The private member
     634         * @param string $name The private member to get, and optionally process.
     635         * @return mixed       The private member.
    641636         */
    642637        public function __get( $name ) {
    643638                if ( 'col_info' === $name ) {
     
    652647         *
    653648         * @since 3.5.0
    654649         *
    655          * @param string $name  The private member to set
    656          * @param mixed  $value The value to set
     650         * @param string $name  The private member to set.
     651         * @param mixed  $value The value to set.
    657652         */
    658653        public function __set( $name, $value ) {
    659654                $protected_members = array(
     
    672667         *
    673668         * @since 3.5.0
    674669         *
    675          * @param string $name  The private member to check
     670         * @param string $name  The private member to check.
    676671         *
    677          * @return bool If the member is set or not
     672         * @return bool         If the member is set or not.
    678673         */
    679674        public function __isset( $name ) {
    680675                return isset( $this->$name );
     
    730725         *
    731726         * @param string $charset The character set to check.
    732727         * @param string $collate The collation to check.
    733          * @return array {
    734          *     The most appropriate character set and collation to use.
    735          *
    736          *     @type string $charset Character set.
    737          *     @type string $collate Collation.
    738          * }
     728         * @return array          The most appropriate character set and collation to use.
    739729         */
    740730        public function determine_charset( $charset, $collate ) {
    741731                if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) {
     
    773763         *
    774764         * @since 3.1.0
    775765         *
    776          * @param resource $dbh     The resource given by mysql_connect
     766         * @param resource $dbh     The resource given by mysql_connect.
    777767         * @param string   $charset Optional. The character set. Default null.
    778768         * @param string   $collate Optional. The collation. Default null.
    779769         */
     
    817807        /**
    818808         * Change the current SQL mode, and ensure its WordPress compatibility.
    819809         *
    820          * If no modes are passed, it will ensure the current MySQL server
    821          * modes are compatible.
     810         * If no modes are passed, it will ensure the current MySQL server modes are compatible.
    822811         *
    823812         * @since 3.9.0
    824813         *
     
    886875         *
    887876         * @param string $prefix          Alphanumeric name for the new prefix.
    888877         * @param bool   $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not.
    889          * @return string|WP_Error Old prefix or WP_Error on error
     878         * @return string|WP_Error        Old prefix or WP_Error on error.
    890879         */
    891880        public function set_prefix( $prefix, $set_table_names = true ) {
    892881
     
    931920         *
    932921         * @param int $blog_id
    933922         * @param int $network_id Optional.
    934          * @return int previous blog id
     923         * @return int            previous blog id.
    935924         */
    936925        public function set_blog_id( $blog_id, $network_id = 0 ) {
    937926                if ( ! empty( $network_id ) ) {
     
    959948         *
    960949         * @since 3.0.0
    961950         * @param int $blog_id Optional.
    962          * @return string Blog prefix.
     951         * @return string      Blog prefix.
    963952         */
    964953        public function get_blog_prefix( $blog_id = null ) {
    965954                if ( is_multisite() ) {
     
    980969        /**
    981970         * Returns an array of WordPress tables.
    982971         *
    983          * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
    984          * override the WordPress users and usermeta tables that would otherwise
    985          * be determined by the prefix.
     972         * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to override the WordPress users and usermeta
     973         * tables that would otherwise be determined by the prefix.
    986974         *
    987          * The scope argument can take one of the following:
     975         * The $scope argument can take one of the following:
    988976         *
    989977         * 'all' - returns 'all' and 'global' tables. No old tables are returned.
    990978         * 'blog' - returns the blog-level tables for the queried blog.
     
    1002990         * @param bool   $prefix  Optional. Whether to include table prefixes. Default true. If blog
    1003991         *                        prefix is requested, then the custom users and usermeta tables will be mapped.
    1004992         * @param int    $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested.
    1005          * @return array Table names. When a prefix is requested, the key is the unprefixed table name.
     993         * @return array          Table names. When a prefix is requested, the key is the unprefixed table name.
    1006994         */
    1007995        public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
    1008996                switch ( $scope ) {
     
    10621050        /**
    10631051         * Selects a database using the current database connection.
    10641052         *
    1065          * The database name will be changed based on the current database
    1066          * connection. On failure, the execution will bail and display an DB error.
     1053         * The database name will be changed based on the current database connection. On failure, the execution will
     1054         * bail and display a DB error.
    10671055         *
    10681056         * @since 0.71
    10691057         *
     
    11491137         * @see mysql_real_escape_string()
    11501138         * @since 2.8.0
    11511139         *
    1152          * @param  string $string to escape
    1153          * @return string escaped
     1140         * @param  string $string String to escape.
     1141         * @return string         Escaped string.
    11541142         */
    11551143        function _real_escape( $string ) {
    11561144                if ( $this->dbh ) {
     
    11771165         * Escape data. Works on arrays.
    11781166         *
    11791167         * @uses wpdb::_real_escape()
    1180          * @since 2.8.0
     1168         * @since  2.8.0
    11811169         *
    1182          * @param  string|array $data
    1183          * @return string|array escaped
     1170         * @param  string|array $data Data to escape.
     1171         * @return string|array       Escaped data, in the same type as supplied.
    11841172         */
    11851173        public function _escape( $data ) {
    11861174                if ( is_array( $data ) ) {
     
    12311219        }
    12321220
    12331221        /**
    1234          * Escapes content by reference for insertion into the database, for security
     1222         * Escapes content by reference for insertion into the database, for security.
    12351223         *
    12361224         * @uses wpdb::_real_escape()
    12371225         *
    12381226         * @since 2.3.0
    12391227         *
    1240          * @param string $string to escape
     1228         * @param string $string String to escape.
    12411229         */
    12421230        public function escape_by_ref( &$string ) {
    12431231                if ( ! is_float( $string ) ) {
     
    12461234        }
    12471235
    12481236        /**
    1249          * Prepares a SQL query for safe execution. Uses sprintf()-like syntax.
     1237         * Prepares a SQL query for safe execution.
    12501238         *
    1251          * The following placeholders can be used in the query string:
     1239         * Uses sprintf()-like syntax. The following placeholders can be used in the query string:
    12521240         *   %d (integer)
    12531241         *   %f (float)
    12541242         *   %s (string)
    12551243         *
    1256          * All placeholders MUST be left unquoted in the query string. A corresponding argument
    1257          * MUST be passed for each placeholder.
     1244         * All placeholders MUST be left unquoted in the query string. A corresponding argument MUST be passed for each
     1245         * placeholder.
    12581246         *
    1259          * For compatibility with old behavior, numbered or formatted string placeholders (eg, %1$s, %5s)
    1260          * will not have quotes added by this function, so should be passed with appropriate quotes around
    1261          * them for your usage.
     1247         * Note: There is one exception to the above: for compatibility with old behavior, older-style numbered or formatted
     1248         * string placeholders (eg, %1$s, %5s) will not have quotes added by this function, so should be passed with
     1249         * appropriate quotes around them.
    12621250         *
    12631251         * Literal percentage signs (%) in the query string must be written as %%. Percentage wildcards (for example,
    12641252         * to use in LIKE syntax) must be passed via a substitution argument containing the complete LIKE string, these
    12651253         * cannot be inserted directly in the query string. Also see wpdb::esc_like().
    12661254         *
    1267          * Arguments may be passed as individual arguments to the method, or as a single array containing
    1268          * all arguments. A combination of the two is not supported.
     1255         * Arguments may be passed as individual arguments to the method, or as a single array containing all arguments.
     1256         * A combination of the two is not supported.
    12691257         *
    12701258         * Examples:
    12711259         *     $wpdb->prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d OR `other_field` LIKE %s", array( 'foo', 1337, '%bar' ) );
     
    12771265         *              by updating the function signature. The second parameter was changed
    12781266         *              from `$args` to `...$args`.
    12791267         *
    1280          * @param string      $query   Query statement with sprintf()-like placeholders
    1281          * @param array|mixed $args    The array of variables to substitute into the query's placeholders
    1282          *                             if being called with an array of arguments, or the first variable
    1283          *                             to substitute into the query's placeholders if being called with
     1268         * @param string      $query   Query statement with sprintf()-like placeholders.
     1269         * @param array|mixed $args    The array of variables to substitute into the query's placeholders if being called
     1270         *                             with an array of arguments, or the first variable to substitute into the query's
     1271         *                             placeholders if being called with individual arguments.
     1272         * @param mixed       ...$args Further variables to substitute into the query's placeholders if being called with
    12841273         *                             individual arguments.
    1285          * @param mixed       ...$args Further variables to substitute into the query's placeholders
    1286          *                             if being called with individual arguments.
    1287          * @return string|void Sanitized query string, if there is a query to prepare.
     1274         *
     1275         * @return string|void         Sanitized query string, if there is a query to prepare.
    12881276         */
    12891277        public function prepare( $query, ...$args ) {
    12901278                if ( is_null( $query ) ) {
     
    14121400         *
    14131401         * @param string $text The raw text to be escaped. The input typed by the user should have no
    14141402         *                     extra or deleted slashes.
    1415          * @return string Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
    1416          *                or real_escape next.
     1403         * @return string      Text in the form of a LIKE phrase. The output is not SQL safe. Call $wpdb::prepare()
     1404         *                     or real_escape next.
    14171405         */
    14181406        public function esc_like( $text ) {
    14191407                return addcslashes( $text, '_%\\' );
     
    14231411         * Print SQL/DB error.
    14241412         *
    14251413         * @since 0.71
    1426          * @global array $EZSQL_ERROR Stores error information of query and error string.
     1414         * @global array $EZSQL_ERROR Stores error information of query and error string
    14271415         *
    1428          * @param string $str The error to display.
    1429          * @return void|false Void if the showing of errors is enabled, false if disabled.
     1416         * @param string $str The error to display
     1417         * @return false|void False if the showing of errors is disabled.
    14301418         */
    14311419        public function print_error( $str = '' ) {
    14321420                global $EZSQL_ERROR;
     
    14961484        /**
    14971485         * Enables showing of database errors.
    14981486         *
    1499          * This function should be used only to enable showing of errors.
    1500          * wpdb::hide_errors() should be used instead for hiding of errors. However,
    1501          * this function can be used to enable and disable showing of database
    1502          * errors.
     1487         * This function should be used only to enable showing of errors. wpdb::hide_errors() should be used instead for
     1488         * hiding of errors. However, this function can be used to enable and disable showing of database errors.
    15031489         *
    1504          * @since 0.71
    15051490         * @see wpdb::hide_errors()
    15061491         *
    1507          * @param bool $show Whether to show or hide errors
    1508          * @return bool Old value for showing errors.
     1492         * @since 0.71
     1493         *
     1494         * @param bool $show Whether to show or hide errors.
     1495         * @return bool      Whether showing of errors was previously active.
    15091496         */
    15101497        public function show_errors( $show = true ) {
    15111498                $errors            = $this->show_errors;
     
    15211508         * @since 0.71
    15221509         * @see wpdb::show_errors()
    15231510         *
    1524          * @return bool Whether showing of errors was active
     1511         * @return bool Whether showing of errors was previously active.
    15251512         */
    15261513        public function hide_errors() {
    15271514                $show              = $this->show_errors;
     
    15321519        /**
    15331520         * Whether to suppress database errors.
    15341521         *
    1535          * By default database errors are suppressed, with a simple
    1536          * call to this function they can be enabled.
     1522         * By default database errors are suppressed, with a simple call to this function they can be enabled.
    15371523         *
    15381524         * @since 2.5.0
    15391525         * @see wpdb::hide_errors()
     1526         *
    15401527         * @param bool $suppress Optional. New value. Defaults to true.
    15411528         * @return bool Old value
    15421529         */
     
    15801567        /**
    15811568         * Connect to and select database.
    15821569         *
    1583          * If $allow_bail is false, the lack of database connection will need
    1584          * to be handled manually.
     1570         * If $allow_bail is false, the lack of database connection will need to be handled manually.
    15851571         *
    15861572         * @since 3.0.0
    15871573         * @since 3.9.0 $allow_bail parameter added.
    15881574         *
    15891575         * @param bool $allow_bail Optional. Allows the function to bail. Default true.
    1590          * @return bool True with a successful connection, false on failure.
     1576         * @return bool            True with a successful connection, false on failure.
    15911577         */
    15921578        public function db_connect( $allow_bail = true ) {
    15931579                $this->is_mysql = true;
     
    17171703        /**
    17181704         * Parse the DB_HOST setting to interpret it for mysqli_real_connect.
    17191705         *
    1720          * mysqli_real_connect doesn't support the host param including a port or
    1721          * socket like mysql_connect does. This duplicates how mysql_connect detects
    1722          * a port and/or socket file.
     1706         * mysqli_real_connect doesn't support the host param including a port or socket like mysql_connect does. This
     1707         * duplicates how mysql_connect detects a port and/or socket file.
    17231708         *
    17241709         * @since 4.9.0
    17251710         *
     
    17351720
    17361721                // First peel off the socket parameter from the right, if it exists.
    17371722                $socket_pos = strpos( $host, ':/' );
    1738                 if ( false !== $socket_pos ) {
     1723                if ( $socket_pos !== false ) {
    17391724                        $socket = substr( $host, $socket_pos + 1 );
    17401725                        $host   = substr( $host, 0, $socket_pos );
    17411726                }
     
    17711756        /**
    17721757         * Checks that the connection to the database is still up. If not, try to reconnect.
    17731758         *
    1774          * If this function is unable to reconnect, it will forcibly die, or if after the
    1775          * the {@see 'template_redirect'} hook has been fired, return false instead.
     1759         * If this function is unable to reconnect, it will forcibly die, or if after the {@see 'template_redirect'} hook
     1760         * has been fired, return false instead.
    17761761         *
    1777          * If $allow_bail is false, the lack of database connection will need
    1778          * to be handled manually.
     1762         * If $allow_bail is false, the lack of database connection will need to be handled manually.
    17791763         *
    17801764         * @since 3.9.0
    17811765         *
     
    18021786                }
    18031787
    18041788                for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) {
    1805                         // On the last try, re-enable warnings. We want to see a single instance
    1806                         // of the "unable to connect" message on the bail() screen, if it appears.
     1789                        // On the last try, re-enable warnings. We want to see a single instance of the
     1790                        // "unable to connect" message on the bail() screen, if it appears.
    18071791                        if ( $this->reconnect_retries === $tries && WP_DEBUG ) {
    18081792                                error_reporting( $error_reporting );
    18091793                        }
     
    18531837                // We weren't able to reconnect, so we better bail.
    18541838                $this->bail( $message, 'db_connect_fail' );
    18551839
    1856                 // Call dead_db() if bail didn't die, because this database is no more.
    1857                 // It has ceased to be (at least temporarily).
     1840                // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).
    18581841                dead_db();
    18591842        }
    18601843
     
    18661849         * @since 0.71
    18671850         *
    18681851         * @param string $query Database query
    1869          * @return int|bool Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows
    1870          *                  affected/selected for all other queries. Boolean false on error.
     1852         * @return int|bool     Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows
     1853         *                      affected/selected for all other queries. Boolean false on error.
    18711854         */
    18721855        public function query( $query ) {
    18731856                if ( ! $this->ready ) {
     
    19971980                                }
    19981981                        }
    19991982
    2000                         // Log number of rows the query returned
    2001                         // and return number of rows selected.
     1983                        // Log number of rows the query returned and return number of rows selected.
    20021984                        $this->num_rows = $num_rows;
    20031985                        $return_val     = $num_rows;
    20041986                }
     
    21132095         * @since 4.8.3
    21142096         *
    21152097         * @param string $query The query to escape.
    2116          * @return string The query with the placeholder escape string inserted where necessary.
     2098         * @return string       The query with the placeholder escape string inserted where necessary.
    21172099         */
    21182100        public function add_placeholder_escape( $query ) {
    21192101                /*
     
    21292111         * @since 4.8.3
    21302112         *
    21312113         * @param string $query The query from which the placeholder will be removed.
    2132          * @return string The query with the placeholder removed.
     2114         * @return string       The query with the placeholder removed.
    21332115         */
    21342116        public function remove_placeholder_escape( $query ) {
    21352117                return str_replace( $this->placeholder_escape(), '%', $query );
     
    21382120        /**
    21392121         * Insert a row into a table.
    21402122         *
     2123         * Examples:
    21412124         *     wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
    21422125         *     wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
    21432126         *
     
    21462129         * @see wpdb::$field_types
    21472130         * @see wp_set_wpdb_vars()
    21482131         *
    2149          * @param string       $table  Table name
     2132         * @param string       $table  Table name.
    21502133         * @param array        $data   Data to insert (in column => value pairs).
    21512134         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    2152          *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
     2135         *                             Sending a null value will cause the column to be set to NULL - the corresponding
     2136         *                             format is ignored in this case.
    21532137         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
    21542138         *                             If string, that format will be used for all of the values in $data.
    21552139         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    2156          *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
    2157          * @return int|false The number of rows inserted, or false on error.
     2140         *                             If omitted, all values in $data will be treated as strings unless otherwise
     2141         *                             specified in wpdb::$field_types.
     2142         * @return int|false           The number of rows inserted, or false on error.
    21582143         */
    21592144        public function insert( $table, $data, $format = null ) {
    21602145                return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' );
     
    21632148        /**
    21642149         * Replace a row into a table.
    21652150         *
     2151         * Examples:
    21662152         *     wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
    21672153         *     wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
    21682154         *
     
    21712157         * @see wpdb::$field_types
    21722158         * @see wp_set_wpdb_vars()
    21732159         *
    2174          * @param string       $table  Table name
     2160         * @param string       $table  Table name.
    21752161         * @param array        $data   Data to insert (in column => value pairs).
    21762162         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    2177          *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
     2163         *                             Sending a null value will cause the column to be set to NULL - the corresponding
     2164         *                             format is ignored in this case.
    21782165         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
    21792166         *                             If string, that format will be used for all of the values in $data.
    21802167         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    2181          *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
    2182          * @return int|false The number of rows affected, or false on error.
     2168         *                             If omitted, all values in $data will be treated as strings unless otherwise
     2169         *                             specified in wpdb::$field_types.
     2170         * @return int|false           The number of rows affected, or false on error.
    21832171         */
    21842172        public function replace( $table, $data, $format = null ) {
    21852173                return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' );
     
    21982186         * @param string       $table  Table name
    21992187         * @param array        $data   Data to insert (in column => value pairs).
    22002188         *                             Both $data columns and $data values should be "raw" (neither should be SQL escaped).
    2201          *                             Sending a null value will cause the column to be set to NULL - the corresponding format is ignored in this case.
     2189         *                             Sending a null value will cause the column to be set to NULL - the corresponding
     2190         *                             format is ignored in this case.
    22022191         * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data.
    22032192         *                             If string, that format will be used for all of the values in $data.
    22042193         *                             A format is one of '%d', '%f', '%s' (integer, float, string).
    2205          *                             If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     2194         *                             If omitted, all values in $data will be treated as strings unless otherwise
     2195         *                             specified in wpdb::$field_types.
    22062196         * @param string $type         Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
    22072197         * @return int|false The number of rows affected, or false on error.
    22082198         */
     
    22402230        }
    22412231
    22422232        /**
    2243          * Update a row in the table
     2233         * Update a row in the table.
    22442234         *
     2235         * Examples:
    22452236         *     wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) )
    22462237         *     wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
    22472238         *
     
    22582249         * @param array        $where        A named array of WHERE clauses (in column => value pairs).
    22592250         *                                   Multiple clauses will be joined with ANDs.
    22602251         *                                   Both $where columns and $where values should be "raw".
    2261          *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
     2252         *                                   Sending a null value will create an IS NULL comparison - the corresponding
     2253         *                                   format will be ignored in this case.
    22622254         * @param array|string $format       Optional. An array of formats to be mapped to each of the values in $data.
    22632255         *                                   If string, that format will be used for all of the values in $data.
    22642256         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    2265          *                                   If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
     2257         *                                   If omitted, all values in $data will be treated as strings unless otherwise
     2258         *                                   specified in wpdb::$field_types.
    22662259         * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where.
    22672260         *                                   If string, that format will be used for all of the items in $where.
    22682261         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    22692262         *                                   If omitted, all values in $where will be treated as strings.
    2270          * @return int|false The number of rows updated, or false on error.
     2263         * @return int|false                 The number of rows updated, or false on error.
    22712264         */
    22722265        public function update( $table, $data, $where, $format = null, $where_format = null ) {
    22732266                if ( ! is_array( $data ) || ! is_array( $where ) ) {
     
    23292322         * @param array        $where        A named array of WHERE clauses (in column => value pairs).
    23302323         *                                   Multiple clauses will be joined with ANDs.
    23312324         *                                   Both $where columns and $where values should be "raw".
    2332          *                                   Sending a null value will create an IS NULL comparison - the corresponding format will be ignored in this case.
     2325         *                                   Sending a null value will create an IS NULL comparison - the corresponding
     2326         *                                   format will be ignored in this case.
    23332327         * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where.
    23342328         *                                   If string, that format will be used for all of the items in $where.
    23352329         *                                   A format is one of '%d', '%f', '%s' (integer, float, string).
    2336          *                                   If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
    2337          * @return int|false The number of rows updated, or false on error.
     2330         *                                   If omitted, all values in $data will be treated as strings unless otherwise
     2331         *                                   specified in wpdb::$field_types.
     2332         * @return int|false                 The number of rows updated, or false on error.
    23382333         */
    23392334        public function delete( $table, $where, $where_format = null ) {
    23402335                if ( ! is_array( $where ) ) {
     
    23692364        /**
    23702365         * Processes arrays of field/value pairs and field formats.
    23712366         *
    2372          * This is a helper method for wpdb's CRUD methods, which take field/value
    2373          * pairs for inserts, updates, and where clauses. This method first pairs
    2374          * each value with a format. Then it determines the charset of that field,
    2375          * using that to determine if any invalid text would be stripped. If text is
    2376          * stripped, then field processing is rejected and the query fails.
     2367         * This is a helper method for wpdb's CRUD methods, which take field/value pairs for inserts, updates, and where
     2368         * clauses. This method first pairs each value with a format. Then it determines the charset of that field, using
     2369         * that to determine if any invalid text would be stripped. If text is stripped, then field processing is rejected
     2370         * and the query fails.
    23772371         *
    23782372         * @since 4.2.0
    23792373         *
     
    23802374         * @param string $table  Table name.
    23812375         * @param array  $data   Field/value pair.
    23822376         * @param mixed  $format Format for each field.
    2383          * @return array|false Returns an array of fields that contain paired values
    2384          *                    and formats. Returns false for invalid values.
     2377         *
     2378         * @return array|false   Returns an array of fields that contain paired value and formats. Returns false for
     2379         *                       invalid values.
    23852380         */
    23862381        protected function process_fields( $table, $data, $format ) {
    23872382                $data = $this->process_field_formats( $data, $format );
     
    24152410         *
    24162411         * @param array $data   Array of fields to values.
    24172412         * @param mixed $format Formats to be mapped to the values in $data.
    2418          * @return array Array, keyed by field names with values being an array
    2419          *               of 'value' and 'format' keys.
     2413         * @return array        Array, keyed by field names with values being an array of 'value' and 'format' keys.
    24202414         */
    24212415        protected function process_field_formats( $data, $format ) {
    24222416                $formats          = (array) $format;
     
    24442438        }
    24452439
    24462440        /**
    2447          * Adds field charsets to field/value/format arrays generated by
    2448          * the wpdb::process_field_formats() method.
     2441         * Adds field charsets to field/value/format arrays generated by the wpdb::process_field_formats() method.
    24492442         *
    24502443         * @since 4.2.0
    24512444         *
    24522445         * @param array  $data  As it comes from the wpdb::process_field_formats() method.
    24532446         * @param string $table Table name.
    2454          * @return array|false The same array as $data with additional 'charset' keys.
     2447         * @return array|false  The same array as $data with additional 'charset' keys.
    24552448         */
    24562449        protected function process_field_charsets( $data, $table ) {
    24572450                foreach ( $data as $field => $value ) {
     
    24812474         *
    24822475         * @param array  $data  As it comes from the wpdb::process_field_charsets() method.
    24832476         * @param string $table Table name.
    2484          * @return array|false The same array as $data with additional 'length' keys, or false if
    2485          *                     any of the values were too long for their corresponding field.
     2477         * @return array|false  The same array as $data with additional 'length' keys, or false if
     2478         *                      any of the values were too long for their corresponding field.
    24862479         */
    24872480        protected function process_field_lengths( $data, $table ) {
    24882481                foreach ( $data as $field => $value ) {
     
    25082501        /**
    25092502         * Retrieve one variable from the database.
    25102503         *
    2511          * Executes a SQL query and returns the value from the SQL result.
    2512          * If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified.
    2513          * If $query is null, this function returns the value in the specified column and row from the previous SQL result.
     2504         * Executes a SQL query and returns the value from the SQL result. If the SQL result contains more than one column
     2505         * and/or more than one row, the value in the column and row specified is returned. If $query is null, the value
     2506         * in the specified column and row from the previous SQL result is returned.
    25142507         *
    25152508         * @since 0.71
    25162509         *
     
    25172510         * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query.
    25182511         * @param int         $x     Optional. Column of value to return. Indexed from 0.
    25192512         * @param int         $y     Optional. Row of value to return. Indexed from 0.
    2520          * @return string|null Database query result (as string), or null on failure
     2513         * @return string|null       Database query result (as string), or null on failure
    25212514         */
    25222515        public function get_var( $query = null, $x = 0, $y = 0 ) {
    25232516                $this->func_call = "\$db->get_var(\"$query\", $x, $y)";
     
    25462539         *
    25472540         * @since 0.71
    25482541         *
    2549          * @param string|null $query  SQL query.
    2550          * @param string      $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to
    2551          *                            an stdClass object, an associative array, or a numeric array, respectively. Default OBJECT.
    2552          * @param int         $y      Optional. Row to return. Indexed from 0.
     2542         * @param string|null $query      SQL query.
     2543         * @param string      $output     Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
     2544         *                                correspond to a stdClass object, an associative array, or a numeric array,
     2545         *                                respectively. Default OBJECT.
     2546         * @param int         $y          Optional. Row to return. Indexed from 0.
    25532547         * @return array|object|null|void Database query result in format specified by $output or null on failure
    25542548         */
    25552549        public function get_row( $query = null, $output = OBJECT, $y = 0 ) {
     
    25862580        /**
    25872581         * Retrieve one column from the database.
    25882582         *
    2589          * Executes a SQL query and returns the column from the SQL result.
    2590          * If the SQL result contains more than one column, this function returns the column specified.
    2591          * If $query is null, this function returns the specified column from the previous SQL result.
     2583         * Executes a SQL query and returns the column from the SQL result. If the SQL result contains more than one column,
     2584         * this function returns the column specified. If $query is null, this function returns the specified column from
     2585         * the previous SQL result.
    25922586         *
    25932587         * @since 0.71
    25942588         *
    25952589         * @param string|null $query Optional. SQL query. Defaults to previous query.
    25962590         * @param int         $x     Optional. Column to return. Indexed from 0.
    2597          * @return array Database query result. Array indexed from 0 by SQL result row number.
     2591         * @return array             Database query result. Array indexed from 0 by SQL result row number.
    25982592         */
    25992593        public function get_col( $query = null, $x = 0 ) {
    26002594                if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
     
    26222616         *
    26232617         * @since 0.71
    26242618         *
    2625          * @param string $query  SQL query.
    2626          * @param string $output Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.
    2627          *                       With one of the first three, return an array of rows indexed from 0 by SQL result row number.
    2628          *                       Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.
    2629          *                       With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value.
    2630          *                       Duplicate keys are discarded.
    2631          * @return array|object|null Database query results
     2619         * @param string $query      SQL query.
     2620         * @param string $output     Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.
     2621         *                           With one of the first three, return an array of rows indexed from 0 by SQL result row
     2622         *                           number. Each row is an associative array (column => value, ...), a numerically indexed
     2623         *                           array (0 => value, ...), or an object. ( ->column = value ), respectively. With
     2624         *                           OBJECT_K, return an associative array of row objects keyed by the value of each row's
     2625         *                           first column's value. Duplicate keys are discarded.
     2626         * @return array|object|null Database query results.
     2627         *
    26322628         */
    26332629        public function get_results( $query = null, $output = OBJECT ) {
    26342630                $this->func_call = "\$db->get_results(\"$query\", $output)";
     
    26862682         *
    26872683         * @since 4.2.0
    26882684         *
    2689          * @param string $table Table name.
     2685         * @param string $table    Table name.
    26902686         * @return string|WP_Error Table character set, WP_Error object if it couldn't be found.
    26912687         */
    26922688        protected function get_table_charset( $table ) {
     
    27872783         *
    27882784         * @since 4.2.0
    27892785         *
    2790          * @param string $table  Table name.
    2791          * @param string $column Column name.
    2792          * @return string|false|WP_Error Column character set as a string. False if the column has no
    2793          *                               character set. WP_Error object if there was an error.
     2786         * @param string $table          Table name.
     2787         * @param string $column         Column name.
     2788         * @return string|false|WP_Error Column character set as a string. False if the column has no character set.
     2789         *                                WP_Error object if there was an error.
    27942790         */
    27952791        public function get_col_charset( $table, $column ) {
    27962792                $tablekey  = strtolower( $table );
     
    28472843
    28482844        /**
    28492845         * Retrieve the maximum string length allowed in a given column.
     2846         *
    28502847         * The length may either be specified as a byte length or a character length.
    28512848         *
    28522849         * @since 4.2.1
    28532850         *
    2854          * @param string $table  Table name.
    2855          * @param string $column Column name.
     2851         * @param string $table         Table name.
     2852         * @param string $column        Column name.
    28562853         * @return array|false|WP_Error array( 'length' => (int), 'type' => 'byte' | 'char' )
    28572854         *                              false if the column has no length (for example, numeric column)
    28582855         *                              WP_Error object if there was an error.
     
    29382935        /**
    29392936         * Check if a string is ASCII.
    29402937         *
    2941          * The negative regex is faster for non-ASCII strings, as it allows
    2942          * the search to finish as soon as it encounters a non-ASCII character.
     2938         * The negative regex is faster for non-ASCII strings, as it allows the search to finish as soon as it encounters
     2939         * a non-ASCII character.
    29432940         *
    29442941         * @since 4.2.0
    29452942         *
    29462943         * @param string $string String to check.
    2947          * @return bool True if ASCII, false if not.
     2944         * @return bool          True if ASCII, false if not.
    29482945         */
    29492946        protected function check_ascii( $string ) {
    29502947                if ( function_exists( 'mb_check_encoding' ) ) {
     
    29642961         * @since 4.2.0
    29652962         *
    29662963         * @param string $query The query to check.
    2967          * @return bool True if the collation is safe, false if it isn't.
     2964         * @return bool         True if the collation is safe, false if it isn't.
    29682965         */
    29692966        protected function check_safe_collation( $query ) {
    29702967                if ( $this->checking_collation ) {
     
    30203017         *
    30213018         * @since 4.2.0
    30223019         *
    3023          * @param array $data Array of value arrays. Each value array has the keys
    3024          *                    'value' and 'charset'. An optional 'ascii' key can be
    3025          *                    set to false to avoid redundant ASCII checks.
    3026          * @return array|WP_Error The $data parameter, with invalid characters removed from
    3027          *                        each value. This works as a passthrough: any additional keys
    3028          *                        such as 'field' are retained in each value array. If we cannot
    3029          *                        remove invalid characters, a WP_Error object is returned.
     3020         * @param array $data     Array of value arrays. Each value array has the keys 'value' and 'charset'. An optional
     3021         *                        'ascii' key can be set to false to avoid redundant ASCII checks.
     3022         * @return array|WP_Error The $data parameter, with invalid characters removed from each value. This works as a
     3023         *                        passthrough: any additional keys such as 'field' are retained in each value array. If we
     3024         *                        cannot remove invalid characters, a WP_Error object is returned.
    30303025         */
    30313026        protected function strip_invalid_text( $data ) {
    30323027                $db_check_string = false;
     
    30393034                                $truncate_by_byte_length = 'byte' === $value['length']['type'];
    30403035                        } else {
    30413036                                $length = false;
    3042                                 /*
    3043                                  * Since we have no length, we'll never truncate.
    3044                                  * Initialize the variable to false. true would take us
    3045                                  * through an unnecessary (for this case) codepath below.
    3046                                  */
     3037                                // Since we have no length, we'll never truncate. Initialize the variable to false. true would take us
     3038                                // through an unnecessary (for this case) codepath below.
    30473039                                $truncate_by_byte_length = false;
    30483040                        }
    30493041
     
    30593051
    30603052                        $needs_validation = true;
    30613053                        if (
    3062                                 // latin1 can store any byte sequence
     3054                                // latin1 can store any byte sequence.
    30633055                                'latin1' === $charset
    30643056                        ||
    30653057                                // ASCII is always OK.
     
    31823174         *
    31833175         * @since 4.2.0
    31843176         *
    3185          * @param string $query Query to convert.
     3177         * @param string $query    Query to convert.
    31863178         * @return string|WP_Error The converted query, or a WP_Error object if the conversion fails.
    31873179         */
    31883180        protected function strip_invalid_text_from_query( $query ) {
     
    32273219         *
    32283220         * @since 4.2.0
    32293221         *
    3230          * @param string $table  Table name.
    3231          * @param string $column Column name.
    3232          * @param string $value  The text to check.
     3222         * @param string $table    Table name.
     3223         * @param string $column   Column name.
     3224         * @param string $value    The text to check.
    32333225         * @return string|WP_Error The converted string, or a WP_Error object if the conversion fails.
    32343226         */
    32353227        public function strip_invalid_text_for_column( $table, $column, $value ) {
     
    33023294
    33033295                /*
    33043296                 * SHOW TABLE STATUS LIKE and SHOW TABLES LIKE 'wp\_123\_%'
    3305                  * This quoted LIKE operand seldom holds a full table name.
    3306                  * It is usually a pattern for matching a prefix so we just
    3307                  * strip the trailing % and unescape the _ to get 'wp_123_'
    3308                  * which drop-ins can use for routing these SQL statements.
     3297                 * This quoted LIKE operand seldom holds a full table name. It is usually a
     3298                 * pattern for matching a prefix so we just strip the trailing % and unescape
     3299                 * the _ to get 'wp_123_' which drop-ins can use for routing these SQL statements.
    33093300                 */
    33103301                if ( preg_match( '/^\s*SHOW\s+(?:TABLE\s+STATUS|(?:FULL\s+)?TABLES)\s+(?:WHERE\s+Name\s+)?LIKE\s*("|\')((?:[\\\\0-9a-zA-Z$_.-]|[\xC2-\xDF][\x80-\xBF])+)%?\\1/is', $query, $maybe ) ) {
    33113302                        return str_replace( '\\_', '_', $maybe[2] );
     
    33653356         *
    33663357         * @since 0.71
    33673358         *
    3368          * @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
    3369          * @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
     3359         * @param string $info_type  Optional. Type one of name, table, def, max_length, not_null, primary_key,
     3360         *                           multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
     3361         * @param int $col_offset    Optional. 0: col name. 1: which table the col's in. 2: col's max length.
     3362         *                           3: if the col is numeric. 4: col's type
    33703363         * @return mixed Column Results
    33713364         */
    33723365        public function get_col_info( $info_type = 'name', $col_offset = -1 ) {
     
    34173410         *
    34183411         * @since 1.5.0
    34193412         *
    3420          * @param string $message    The error message.
    3421          * @param string $error_code Optional. A computer-readable string to identify the error.
    3422          * @return void|false Void if the showing of errors is enabled, false if disabled.
     3413         * @param string $message    The Error message
     3414         * @param string $error_code Optional. A Computer readable string to identify the error.
     3415         * @return false|void
    34233416         */
    34243417        public function bail( $message, $error_code = '500' ) {
    34253418                if ( $this->show_errors ) {
     
    34613454         *
    34623455         * @since 4.5.0
    34633456         *
    3464          * @return bool True if the connection was successfully closed, false if it wasn't,
    3465          *              or the connection doesn't exist.
     3457         * @return bool True if the connection was successfully closed, false if it wasn't, or if the connection doesn't exist.
    34663458         */
    34673459        public function close() {
    34683460                if ( ! $this->dbh ) {
     
    34893481         *
    34903482         * @since 2.5.0
    34913483         *
    3492          * @global string $wp_version             The WordPress version string.
    3493          * @global string $required_mysql_version The required MySQL version string.
    3494          *
    3495          * @return void|WP_Error
     3484         * @global string $wp_version
     3485         * @global string $required_mysql_version
     3486         * @return WP_Error|void
    34963487         */
    34973488        public function check_database_version() {
    34983489                global $wp_version, $required_mysql_version;
     
    35493540         *
    35503541         * @see wpdb::db_version()
    35513542         *
    3552          * @param string $db_cap The feature to check for. Accepts 'collation',
    3553          *                       'group_concat', 'subqueries', 'set_charset',
     3543         * @param string $db_cap The feature to check for. Accepts 'collation', 'group_concat', 'subqueries', 'set_charset',
    35543544         *                       'utf8mb4', or 'utf8mb4_520'.
    3555          * @return int|false Whether the database feature is supported, false otherwise.
     3545         * @return int|false     Whether the database feature is supported, false otherwise.
    35563546         */
    35573547        public function has_cap( $db_cap ) {
    35583548                $version = $this->db_version();
     
    35943584        /**
    35953585         * Retrieve the name of the function that called wpdb.
    35963586         *
    3597          * Searches up the list of functions until it reaches
    3598          * the one that would most logically had called this method.
     3587         * Searches up the list of functions until it reaches the one that would most logically had called this method.
    35993588         *
    36003589         * @since 2.5.0
    36013590         *