Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r47107 r47122  
    609609        }
    610610
    611         // Use ext/mysqli if it exists unless WP_USE_EXT_MYSQL is defined as true
     611        // Use ext/mysqli if it exists unless WP_USE_EXT_MYSQL is defined as true.
    612612        if ( function_exists( 'mysqli_connect' ) ) {
    613613            $this->use_mysqli = true;
     
    11771177     *
    11781178     * @uses wpdb::_real_escape()
    1179      * @since  2.8.0
     1179     * @since 2.8.0
    11801180     *
    11811181     * @param  string|array $data
     
    13491349        $query = preg_replace( '/(?<!%)%s/', "'%s'", $query ); // Quote the strings, avoiding escaped strings like %%s.
    13501350
    1351         $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/", '%\\2F', $query ); // Force floats to be locale unaware.
     1351        $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/", '%\\2F', $query ); // Force floats to be locale-unaware.
    13521352
    13531353        $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdF]))/", '%%\\1', $query ); // Escape any unescaped percents.
     
    14651465        }
    14661466
    1467         // If there is an error then take note of it
     1467        // If there is an error then take note of it.
    14681468        if ( is_multisite() ) {
    14691469            $msg = sprintf(
     
    15631563            $this->result = null;
    15641564
    1565             // Sanity check before using the handle
     1565            // Sanity check before using the handle.
    15661566            if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) {
    15671567                return;
    15681568            }
    15691569
    1570             // Clear out any results from a multi-query
     1570            // Clear out any results from a multi-query.
    15711571            while ( mysqli_more_results( $this->dbh ) ) {
    15721572                mysqli_next_result( $this->dbh );
     
    17951795        $error_reporting = false;
    17961796
    1797         // Disable warnings, as we don't want to see a multitude of "unable to connect" messages
     1797        // Disable warnings, as we don't want to see a multitude of "unable to connect" messages.
    17981798        if ( WP_DEBUG ) {
    17991799            $error_reporting = error_reporting();
     
    18021802
    18031803        for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) {
    1804             // On the last try, re-enable warnings. We want to see a single instance of the
    1805             // "unable to connect" message on the bail() screen, if it appears.
     1804            // On the last try, re-enable warnings. We want to see a single instance
     1805            // of the "unable to connect" message on the bail() screen, if it appears.
    18061806            if ( $this->reconnect_retries === $tries && WP_DEBUG ) {
    18071807                error_reporting( $error_reporting );
     
    18531853        $this->bail( $message, 'db_connect_fail' );
    18541854
    1855         // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).
     1855        // Call dead_db() if bail didn't die, because this database is no more.
     1856        // It has ceased to be (at least temporarily).
    18561857        dead_db();
    18571858    }
     
    18881889        $this->flush();
    18891890
    1890         // Log how the function was called
     1891        // Log how the function was called.
    18911892        $this->func_call = "\$db->query(\"$query\")";
    18921893
     
    19721973                $this->rows_affected = mysql_affected_rows( $this->dbh );
    19731974            }
    1974             // Take note of the insert_id
     1975            // Take note of the insert_id.
    19751976            if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) {
    19761977                if ( $this->use_mysqli ) {
     
    19801981                }
    19811982            }
    1982             // Return number of rows affected
     1983            // Return number of rows affected.
    19831984            $return_val = $this->rows_affected;
    19841985        } else {
     
    19971998
    19981999            // Log number of rows the query returned
    1999             // and return number of rows selected
     2000            // and return number of rows selected.
    20002001            $this->num_rows = $num_rows;
    20012002            $return_val     = $num_rows;
     
    25292530        }
    25302531
    2531         // Extract var out of cached results based x,y vals
     2532        // Extract var out of cached results based x,y vals.
    25322533        if ( ! empty( $this->last_result[ $y ] ) ) {
    25332534            $values = array_values( get_object_vars( $this->last_result[ $y ] ) );
    25342535        }
    25352536
    2536         // If there is a value return it else return null
     2537        // If there is a value return it else return null.
    25372538        return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ] : null;
    25382539    }
     
    25752576            return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null;
    25762577        } elseif ( strtoupper( $output ) === OBJECT ) {
    2577             // Back compat for OBJECT being previously case insensitive.
     2578            // Back compat for OBJECT being previously case-insensitive.
    25782579            return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
    25792580        } else {
     
    26052606
    26062607        $new_array = array();
    2607         // Extract the column values
     2608        // Extract the column values.
    26082609        if ( $this->last_result ) {
    26092610            for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
     
    26442645        $new_array = array();
    26452646        if ( $output == OBJECT ) {
    2646             // Return an integer-keyed array of row objects
     2647            // Return an integer-keyed array of row objects.
    26472648            return $this->last_result;
    26482649        } elseif ( $output == OBJECT_K ) {
    2649             // Return an array of row objects with keys from column 1
    2650             // (Duplicates are discarded)
     2650            // Return an array of row objects with keys from column 1.
     2651            // (Duplicates are discarded.)
    26512652            if ( $this->last_result ) {
    26522653                foreach ( $this->last_result as $row ) {
     
    26642665                foreach ( (array) $this->last_result as $row ) {
    26652666                    if ( $output == ARRAY_N ) {
    2666                         // ...integer-keyed row arrays
     2667                        // ...integer-keyed row arrays.
    26672668                        $new_array[] = array_values( get_object_vars( $row ) );
    26682669                    } else {
    2669                         // ...column name-keyed row arrays
     2670                        // ...column name-keyed row arrays.
    26702671                        $new_array[] = get_object_vars( $row );
    26712672                    }
     
    26742675            return $new_array;
    26752676        } elseif ( strtoupper( $output ) === OBJECT ) {
    2676             // Back compat for OBJECT being previously case insensitive.
     2677            // Back compat for OBJECT being previously case-insensitive.
    26772678            return $this->last_result;
    26782679        }
     
    30383039            } else {
    30393040                $length = false;
    3040                 // Since we have no length, we'll never truncate.
    3041                 // Initialize the variable to false. true would take us
    3042                 // through an unnecessary (for this case) codepath below.
     3041                /*
     3042                 * Since we have no length, we'll never truncate.
     3043                 * Initialize the variable to false. true would take us
     3044                 * through an unnecessary (for this case) codepath below.
     3045                 */
    30433046                $truncate_by_byte_length = false;
    30443047            }
     
    31963199            }
    31973200
    3198             // We can't reliably strip text from tables containing binary/blob columns
     3201            // We can't reliably strip text from tables containing binary/blob columns.
    31993202            if ( 'binary' === $charset ) {
    32003203                return $query;
     
    32973300        }
    32983301
    3299         // SHOW TABLE STATUS LIKE and SHOW TABLES LIKE 'wp\_123\_%'
    3300         // This quoted LIKE operand seldom holds a full table name.
    3301         // It is usually a pattern for matching a prefix so we just
    3302         // strip the trailing % and unescape the _ to get 'wp_123_'
    3303         // which drop-ins can use for routing these SQL statements.
     3302        /*
     3303         * SHOW TABLE STATUS LIKE and SHOW TABLES LIKE 'wp\_123\_%'
     3304         * This quoted LIKE operand seldom holds a full table name.
     3305         * It is usually a pattern for matching a prefix so we just
     3306         * strip the trailing % and unescape the _ to get 'wp_123_'
     3307         * which drop-ins can use for routing these SQL statements.
     3308         */
    33043309        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 ) ) {
    33053310            return str_replace( '\\_', '_', $maybe[2] );
     
    34913496    public function check_database_version() {
    34923497        global $wp_version, $required_mysql_version;
    3493         // Make sure the server has the required MySQL version
     3498        // Make sure the server has the required MySQL version.
    34943499        if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) {
    34953500            /* translators: 1: WordPress version number, 2: Minimum required MySQL version number. */
Note: See TracChangeset for help on using the changeset viewer.