Changeset 47122 for trunk/src/wp-includes/wp-db.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/wp-db.php (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/wp-db.php
r47107 r47122 609 609 } 610 610 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. 612 612 if ( function_exists( 'mysqli_connect' ) ) { 613 613 $this->use_mysqli = true; … … 1177 1177 * 1178 1178 * @uses wpdb::_real_escape() 1179 * @since 2.8.01179 * @since 2.8.0 1180 1180 * 1181 1181 * @param string|array $data … … 1349 1349 $query = preg_replace( '/(?<!%)%s/', "'%s'", $query ); // Quote the strings, avoiding escaped strings like %%s. 1350 1350 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. 1352 1352 1353 1353 $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdF]))/", '%%\\1', $query ); // Escape any unescaped percents. … … 1465 1465 } 1466 1466 1467 // If there is an error then take note of it 1467 // If there is an error then take note of it. 1468 1468 if ( is_multisite() ) { 1469 1469 $msg = sprintf( … … 1563 1563 $this->result = null; 1564 1564 1565 // Sanity check before using the handle 1565 // Sanity check before using the handle. 1566 1566 if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) { 1567 1567 return; 1568 1568 } 1569 1569 1570 // Clear out any results from a multi-query 1570 // Clear out any results from a multi-query. 1571 1571 while ( mysqli_more_results( $this->dbh ) ) { 1572 1572 mysqli_next_result( $this->dbh ); … … 1795 1795 $error_reporting = false; 1796 1796 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. 1798 1798 if ( WP_DEBUG ) { 1799 1799 $error_reporting = error_reporting(); … … 1802 1802 1803 1803 for ( $tries = 1; $tries <= $this->reconnect_retries; $tries++ ) { 1804 // On the last try, re-enable warnings. We want to see a single instance of the1805 // "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. 1806 1806 if ( $this->reconnect_retries === $tries && WP_DEBUG ) { 1807 1807 error_reporting( $error_reporting ); … … 1853 1853 $this->bail( $message, 'db_connect_fail' ); 1854 1854 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). 1856 1857 dead_db(); 1857 1858 } … … 1888 1889 $this->flush(); 1889 1890 1890 // Log how the function was called 1891 // Log how the function was called. 1891 1892 $this->func_call = "\$db->query(\"$query\")"; 1892 1893 … … 1972 1973 $this->rows_affected = mysql_affected_rows( $this->dbh ); 1973 1974 } 1974 // Take note of the insert_id 1975 // Take note of the insert_id. 1975 1976 if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 1976 1977 if ( $this->use_mysqli ) { … … 1980 1981 } 1981 1982 } 1982 // Return number of rows affected 1983 // Return number of rows affected. 1983 1984 $return_val = $this->rows_affected; 1984 1985 } else { … … 1997 1998 1998 1999 // Log number of rows the query returned 1999 // and return number of rows selected 2000 // and return number of rows selected. 2000 2001 $this->num_rows = $num_rows; 2001 2002 $return_val = $num_rows; … … 2529 2530 } 2530 2531 2531 // Extract var out of cached results based x,y vals 2532 // Extract var out of cached results based x,y vals. 2532 2533 if ( ! empty( $this->last_result[ $y ] ) ) { 2533 2534 $values = array_values( get_object_vars( $this->last_result[ $y ] ) ); 2534 2535 } 2535 2536 2536 // If there is a value return it else return null 2537 // If there is a value return it else return null. 2537 2538 return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ] : null; 2538 2539 } … … 2575 2576 return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null; 2576 2577 } elseif ( strtoupper( $output ) === OBJECT ) { 2577 // Back compat for OBJECT being previously case insensitive.2578 // Back compat for OBJECT being previously case-insensitive. 2578 2579 return $this->last_result[ $y ] ? $this->last_result[ $y ] : null; 2579 2580 } else { … … 2605 2606 2606 2607 $new_array = array(); 2607 // Extract the column values 2608 // Extract the column values. 2608 2609 if ( $this->last_result ) { 2609 2610 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { … … 2644 2645 $new_array = array(); 2645 2646 if ( $output == OBJECT ) { 2646 // Return an integer-keyed array of row objects 2647 // Return an integer-keyed array of row objects. 2647 2648 return $this->last_result; 2648 2649 } 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.) 2651 2652 if ( $this->last_result ) { 2652 2653 foreach ( $this->last_result as $row ) { … … 2664 2665 foreach ( (array) $this->last_result as $row ) { 2665 2666 if ( $output == ARRAY_N ) { 2666 // ...integer-keyed row arrays 2667 // ...integer-keyed row arrays. 2667 2668 $new_array[] = array_values( get_object_vars( $row ) ); 2668 2669 } else { 2669 // ...column name-keyed row arrays 2670 // ...column name-keyed row arrays. 2670 2671 $new_array[] = get_object_vars( $row ); 2671 2672 } … … 2674 2675 return $new_array; 2675 2676 } elseif ( strtoupper( $output ) === OBJECT ) { 2676 // Back compat for OBJECT being previously case insensitive.2677 // Back compat for OBJECT being previously case-insensitive. 2677 2678 return $this->last_result; 2678 2679 } … … 3038 3039 } else { 3039 3040 $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 */ 3043 3046 $truncate_by_byte_length = false; 3044 3047 } … … 3196 3199 } 3197 3200 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. 3199 3202 if ( 'binary' === $charset ) { 3200 3203 return $query; … … 3297 3300 } 3298 3301 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 */ 3304 3309 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 ) ) { 3305 3310 return str_replace( '\\_', '_', $maybe[2] ); … … 3491 3496 public function check_database_version() { 3492 3497 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. 3494 3499 if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) { 3495 3500 /* translators: 1: WordPress version number, 2: Minimum required MySQL version number. */
Note: See TracChangeset
for help on using the changeset viewer.