Changeset 42343 for trunk/src/wp-includes/wp-db.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/wp-db.php
r42228 r42343 242 242 * @var array 243 243 */ 244 var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 245 'terms', 'term_taxonomy', 'term_relationships', 'termmeta', 'commentmeta' ); 244 var $tables = array( 245 'posts', 246 'comments', 247 'links', 248 'options', 249 'postmeta', 250 'terms', 251 'term_taxonomy', 252 'term_relationships', 253 'termmeta', 254 'commentmeta', 255 ); 246 256 247 257 /** … … 272 282 * @var array 273 283 */ 274 var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 275 'sitecategories', 'registration_log', 'blog_versions' ); 284 var $ms_global_tables = array( 285 'blogs', 286 'signups', 287 'site', 288 'sitemeta', 289 'sitecategories', 290 'registration_log', 291 'blog_versions', 292 ); 276 293 277 294 /** … … 529 546 * @var array 530 547 */ 531 protected $incompatible_modes = array( 'NO_ZERO_DATE', 'ONLY_FULL_GROUP_BY', 532 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'TRADITIONAL' ); 548 protected $incompatible_modes = array( 549 'NO_ZERO_DATE', 550 'ONLY_FULL_GROUP_BY', 551 'STRICT_TRANS_TABLES', 552 'STRICT_ALL_TABLES', 553 'TRADITIONAL', 554 ); 533 555 534 556 /** … … 568 590 register_shutdown_function( array( $this, '__destruct' ) ); 569 591 570 if ( WP_DEBUG && WP_DEBUG_DISPLAY ) 592 if ( WP_DEBUG && WP_DEBUG_DISPLAY ) { 571 593 $this->show_errors(); 594 } 572 595 573 596 /* Use ext/mysqli if it exists and: … … 587 610 } 588 611 589 $this->dbuser = $dbuser;612 $this->dbuser = $dbuser; 590 613 $this->dbpassword = $dbpassword; 591 $this->dbname = $dbname;592 $this->dbhost = $dbhost;614 $this->dbname = $dbname; 615 $this->dbhost = $dbhost; 593 616 594 617 // wp-config.php creation will manually connect when ready. … … 620 643 */ 621 644 public function __get( $name ) { 622 if ( 'col_info' === $name ) 645 if ( 'col_info' === $name ) { 623 646 $this->load_col_info(); 647 } 624 648 625 649 return $this->$name; … … 640 664 'check_current_query', 641 665 ); 642 if ( 666 if ( in_array( $name, $protected_members, true ) ) { 643 667 return; 644 668 } … … 679 703 $collate = ''; 680 704 681 if ( function_exists( 'is_multisite') && is_multisite() ) {705 if ( function_exists( 'is_multisite' ) && is_multisite() ) { 682 706 $charset = 'utf8'; 683 707 if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) { … … 752 776 */ 753 777 public function set_charset( $dbh, $charset = null, $collate = null ) { 754 if ( ! isset( $charset ) ) 778 if ( ! isset( $charset ) ) { 755 779 $charset = $this->charset; 756 if ( ! isset( $collate ) ) 780 } 781 if ( ! isset( $collate ) ) { 757 782 $collate = $this->collate; 783 } 758 784 if ( $this->has_cap( 'collation' ) && ! empty( $charset ) ) { 759 785 $set_charset_succeeded = true; … … 766 792 if ( $set_charset_succeeded ) { 767 793 $query = $this->prepare( 'SET NAMES %s', $charset ); 768 if ( ! empty( $collate ) ) 794 if ( ! empty( $collate ) ) { 769 795 $query .= $this->prepare( ' COLLATE %s', $collate ); 796 } 770 797 mysqli_query( $dbh, $query ); 771 798 } … … 776 803 if ( $set_charset_succeeded ) { 777 804 $query = $this->prepare( 'SET NAMES %s', $charset ); 778 if ( ! empty( $collate ) ) 805 if ( ! empty( $collate ) ) { 779 806 $query .= $this->prepare( ' COLLATE %s', $collate ); 807 } 780 808 mysql_query( $query, $dbh ); 781 809 } … … 860 888 public function set_prefix( $prefix, $set_table_names = true ) { 861 889 862 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 863 return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); 890 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) { 891 return new WP_Error( 'invalid_db_prefix', 'Invalid database prefix' ); 892 } 864 893 865 894 $old_prefix = is_multisite() ? '' : $prefix; 866 895 867 if ( isset( $this->base_prefix ) ) 896 if ( isset( $this->base_prefix ) ) { 868 897 $old_prefix = $this->base_prefix; 898 } 869 899 870 900 $this->base_prefix = $prefix; 871 901 872 902 if ( $set_table_names ) { 873 foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) 903 foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) { 874 904 $this->$table = $prefixed_table; 875 876 if ( is_multisite() && empty( $this->blogid ) ) 905 } 906 907 if ( is_multisite() && empty( $this->blogid ) ) { 877 908 return $old_prefix; 909 } 878 910 879 911 $this->prefix = $this->get_blog_prefix(); 880 912 881 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) 913 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { 882 914 $this->$table = $prefixed_table; 883 884 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) 915 } 916 917 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { 885 918 $this->$table = $prefixed_table; 919 } 886 920 } 887 921 return $old_prefix; … … 907 941 $this->prefix = $this->get_blog_prefix(); 908 942 909 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) 943 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) { 910 944 $this->$table = $prefixed_table; 911 912 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) 945 } 946 947 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) { 913 948 $this->$table = $prefixed_table; 949 } 914 950 915 951 return $old_blog_id; … … 925 961 public function get_blog_prefix( $blog_id = null ) { 926 962 if ( is_multisite() ) { 927 if ( null === $blog_id ) 963 if ( null === $blog_id ) { 928 964 $blog_id = $this->blogid; 965 } 929 966 $blog_id = (int) $blog_id; 930 if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) 967 if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) { 931 968 return $this->base_prefix; 932 else969 } else { 933 970 return $this->base_prefix . $blog_id . '_'; 971 } 934 972 } else { 935 973 return $this->base_prefix; … … 966 1004 public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { 967 1005 switch ( $scope ) { 968 case 'all' 1006 case 'all': 969 1007 $tables = array_merge( $this->global_tables, $this->tables ); 970 if ( is_multisite() ) 1008 if ( is_multisite() ) { 971 1009 $tables = array_merge( $tables, $this->ms_global_tables ); 1010 } 972 1011 break; 973 case 'blog' 1012 case 'blog': 974 1013 $tables = $this->tables; 975 1014 break; 976 case 'global' 1015 case 'global': 977 1016 $tables = $this->global_tables; 978 if ( is_multisite() ) 1017 if ( is_multisite() ) { 979 1018 $tables = array_merge( $tables, $this->ms_global_tables ); 1019 } 980 1020 break; 981 case 'ms_global' 1021 case 'ms_global': 982 1022 $tables = $this->ms_global_tables; 983 1023 break; 984 case 'old' 1024 case 'old': 985 1025 $tables = $this->old_tables; 986 1026 break; 987 default 1027 default: 988 1028 return array(); 989 1029 } 990 1030 991 1031 if ( $prefix ) { 992 if ( ! $blog_id ) 1032 if ( ! $blog_id ) { 993 1033 $blog_id = $this->blogid; 994 $blog_prefix = $this->get_blog_prefix( $blog_id ); 995 $base_prefix = $this->base_prefix; 1034 } 1035 $blog_prefix = $this->get_blog_prefix( $blog_id ); 1036 $base_prefix = $this->base_prefix; 996 1037 $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); 997 1038 foreach ( $tables as $k => $table ) { 998 if ( in_array( $table, $global_tables ) ) 1039 if ( in_array( $table, $global_tables ) ) { 999 1040 $tables[ $table ] = $base_prefix . $table; 1000 else1041 } else { 1001 1042 $tables[ $table ] = $blog_prefix . $table; 1043 } 1002 1044 unset( $tables[ $k ] ); 1003 1045 } 1004 1046 1005 if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) 1047 if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) { 1006 1048 $tables['users'] = CUSTOM_USER_TABLE; 1007 1008 if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) 1049 } 1050 1051 if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) { 1009 1052 $tables['usermeta'] = CUSTOM_USER_META_TABLE; 1053 } 1010 1054 } 1011 1055 … … 1025 1069 */ 1026 1070 public function select( $db, $dbh = null ) { 1027 if ( is_null( $dbh) )1071 if ( is_null( $dbh ) ) { 1028 1072 $dbh = $this->dbh; 1073 } 1029 1074 1030 1075 if ( $this->use_mysqli ) { … … 1052 1097 /* translators: 1: database user, 2: database name */ 1053 1098 __( 'Does the user %1$s have permission to use the %2$s database?' ), 1054 '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) 1099 '<code>' . htmlspecialchars( $this->dbuser, ENT_QUOTES ) . '</code>', 1055 1100 '<code>' . htmlspecialchars( $db, ENT_QUOTES ) . '</code>' 1056 1101 ) . "</li>\n"; … … 1060 1105 __( 'On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?' ), 1061 1106 htmlspecialchars( $db, ENT_QUOTES ) 1062 ) . "</li>\n";1107 ) . "</li>\n"; 1063 1108 1064 1109 $message .= "</ul>\n"; … … 1089 1134 */ 1090 1135 function _weak_escape( $string ) { 1091 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) 1136 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { 1092 1137 _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' ); 1138 } 1093 1139 return addslashes( $string ); 1094 1140 } … … 1138 1184 foreach ( $data as $k => $v ) { 1139 1185 if ( is_array( $v ) ) { 1140 $data[ $k] = $this->_escape( $v );1186 $data[ $k ] = $this->_escape( $v ); 1141 1187 } else { 1142 $data[ $k] = $this->_real_escape( $v );1188 $data[ $k ] = $this->_real_escape( $v ); 1143 1189 } 1144 1190 } … … 1164 1210 */ 1165 1211 public function escape( $data ) { 1166 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) 1212 if ( func_num_args() === 1 && function_exists( '_deprecated_function' ) ) { 1167 1213 _deprecated_function( __METHOD__, '3.6.0', 'wpdb::prepare() or esc_sql()' ); 1214 } 1168 1215 if ( is_array( $data ) ) { 1169 1216 foreach ( $data as $k => $v ) { 1170 if ( is_array( $v ) ) 1171 $data[$k] = $this->escape( $v, 'recursive' ); 1172 else 1173 $data[$k] = $this->_weak_escape( $v, 'internal' ); 1217 if ( is_array( $v ) ) { 1218 $data[ $k ] = $this->escape( $v, 'recursive' ); 1219 } else { 1220 $data[ $k ] = $this->_weak_escape( $v, 'internal' ); 1221 } 1174 1222 } 1175 1223 } else { … … 1190 1238 */ 1191 1239 public function escape_by_ref( &$string ) { 1192 if ( ! is_float( $string ) ) 1240 if ( ! is_float( $string ) ) { 1193 1241 $string = $this->_real_escape( $string ); 1242 } 1194 1243 } 1195 1244 … … 1245 1294 if ( is_array( $args[0] ) && count( $args ) == 1 ) { 1246 1295 $passed_as_array = true; 1247 $args = $args[0];1296 $args = $args[0]; 1248 1297 } 1249 1298 … … 1277 1326 $query = preg_replace( '/(?<!%)%s/', "'%s'", $query ); // Quote the strings, avoiding escaped strings like %%s. 1278 1327 1279 $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/" 1328 $query = preg_replace( "/(?<!%)(%($allowed_format)?f)/", '%\\2F', $query ); // Force floats to be locale unaware. 1280 1329 1281 1330 $query = preg_replace( "/%(?:%|$|(?!($allowed_format)?[sdF]))/", '%%\\1', $query ); // Escape any unescaped percents. … … 1297 1346 */ 1298 1347 wp_load_translations_early(); 1299 _doing_it_wrong( 'wpdb::prepare', 1348 _doing_it_wrong( 1349 'wpdb::prepare', 1300 1350 /* translators: 1: number of placeholders, 2: number of arguments passed */ 1301 sprintf( __( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ), 1351 sprintf( 1352 __( 'The query does not contain the correct number of placeholders (%1$d) for the number of arguments passed (%2$d).' ), 1302 1353 $placeholders, 1303 count( $args ) ), 1354 count( $args ) 1355 ), 1304 1356 '4.8.3' 1305 1357 ); … … 1352 1404 global $EZSQL_ERROR; 1353 1405 1354 if ( ! $str ) {1406 if ( ! $str ) { 1355 1407 if ( $this->use_mysqli ) { 1356 1408 $str = mysqli_error( $this->dbh ); … … 1359 1411 } 1360 1412 } 1361 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 1362 1363 if ( $this->suppress_errors ) 1413 $EZSQL_ERROR[] = array( 1414 'query' => $this->last_query, 1415 'error_str' => $str, 1416 ); 1417 1418 if ( $this->suppress_errors ) { 1364 1419 return false; 1420 } 1365 1421 1366 1422 wp_load_translations_early(); … … 1377 1433 1378 1434 // Are we showing errors? 1379 if ( ! $this->show_errors ) 1435 if ( ! $this->show_errors ) { 1380 1436 return false; 1437 } 1381 1438 1382 1439 // If there is an error then take note of it … … 1423 1480 */ 1424 1481 public function show_errors( $show = true ) { 1425 $errors = $this->show_errors;1482 $errors = $this->show_errors; 1426 1483 $this->show_errors = $show; 1427 1484 return $errors; … … 1439 1496 */ 1440 1497 public function hide_errors() { 1441 $show = $this->show_errors;1498 $show = $this->show_errors; 1442 1499 $this->show_errors = false; 1443 1500 return $show; … … 1456 1513 */ 1457 1514 public function suppress_errors( $suppress = true ) { 1458 $errors = $this->suppress_errors;1515 $errors = $this->suppress_errors; 1459 1516 $this->suppress_errors = (bool) $suppress; 1460 1517 return $errors; … … 1467 1524 */ 1468 1525 public function flush() { 1469 $this->last_result = array();1470 $this->col_info = null;1471 $this->last_query = null;1526 $this->last_result = array(); 1527 $this->col_info = null; 1528 $this->last_query = null; 1472 1529 $this->rows_affected = $this->num_rows = 0; 1473 $this->last_error = '';1530 $this->last_error = ''; 1474 1531 1475 1532 if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { … … 1478 1535 1479 1536 // Sanity check before using the handle 1480 if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) {1537 if ( empty( $this->dbh ) || ! ( $this->dbh instanceof mysqli ) ) { 1481 1538 return; 1482 1539 } … … 1510 1567 * $new_link parameter exists for mysqli_* functions. 1511 1568 */ 1512 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;1569 $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; 1513 1570 $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; 1514 1571 … … 1546 1603 /* 1547 1604 * It's possible ext/mysqli is misconfigured. Fall back to ext/mysql if: 1548 1549 1550 1551 1605 * - We haven't previously connected, and 1606 * - WP_USE_EXT_MYSQL isn't set to false, and 1607 * - ext/mysql is loaded. 1608 */ 1552 1609 $attempt_fallback = true; 1553 1610 … … 1648 1705 if ( $socket_pos !== false ) { 1649 1706 $socket = substr( $host, $socket_pos + 1 ); 1650 $host = substr( $host, 0, $socket_pos );1707 $host = substr( $host, 0, $socket_pos ); 1651 1708 } 1652 1709 … … 1662 1719 1663 1720 $matches = array(); 1664 $result = preg_match( $pattern, $host, $matches );1721 $result = preg_match( $pattern, $host, $matches ); 1665 1722 1666 1723 if ( 1 !== $result ) { … … 1866 1923 if ( $this->last_error ) { 1867 1924 // Clear insert_id on a subsequent failed insert. 1868 if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) 1925 if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { 1869 1926 $this->insert_id = 0; 1927 } 1870 1928 1871 1929 $this->print_error(); … … 1895 1953 if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { 1896 1954 while ( $row = mysqli_fetch_object( $this->result ) ) { 1897 $this->last_result[ $num_rows] = $row;1955 $this->last_result[ $num_rows ] = $row; 1898 1956 $num_rows++; 1899 1957 } 1900 1958 } elseif ( is_resource( $this->result ) ) { 1901 1959 while ( $row = mysql_fetch_object( $this->result ) ) { 1902 $this->last_result[ $num_rows] = $row;1960 $this->last_result[ $num_rows ] = $row; 1903 1961 $num_rows++; 1904 1962 } … … 2162 2220 2163 2221 $conditions[] = "`$field` = " . $value['format']; 2164 $values[] = $value['value'];2165 } 2166 2167 $fields = implode( ', ', $fields );2222 $values[] = $value['value']; 2223 } 2224 2225 $fields = implode( ', ', $fields ); 2168 2226 $conditions = implode( ' AND ', $conditions ); 2169 2227 … … 2214 2272 2215 2273 $conditions[] = "`$field` = " . $value['format']; 2216 $values[] = $value['value'];2274 $values[] = $value['value']; 2217 2275 } 2218 2276 … … 2389 2447 2390 2448 // Extract var out of cached results based x,y vals 2391 if ( ! empty( $this->last_result[$y] ) ) {2392 $values = array_values( get_object_vars( $this->last_result[ $y] ) );2449 if ( ! empty( $this->last_result[ $y ] ) ) { 2450 $values = array_values( get_object_vars( $this->last_result[ $y ] ) ); 2393 2451 } 2394 2452 2395 2453 // If there is a value return it else return null 2396 return ( isset( $values[ $x] ) && $values[$x] !== '' ) ? $values[$x] : null;2454 return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ] : null; 2397 2455 } 2398 2456 … … 2423 2481 } 2424 2482 2425 if ( ! isset( $this->last_result[$y] ) )2483 if ( ! isset( $this->last_result[ $y ] ) ) { 2426 2484 return null; 2485 } 2427 2486 2428 2487 if ( $output == OBJECT ) { 2429 return $this->last_result[ $y] ? $this->last_result[$y] : null;2488 return $this->last_result[ $y ] ? $this->last_result[ $y ] : null; 2430 2489 } elseif ( $output == ARRAY_A ) { 2431 return $this->last_result[ $y] ? get_object_vars( $this->last_result[$y] ) : null;2490 return $this->last_result[ $y ] ? get_object_vars( $this->last_result[ $y ] ) : null; 2432 2491 } elseif ( $output == ARRAY_N ) { 2433 return $this->last_result[ $y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;2492 return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null; 2434 2493 } elseif ( strtoupper( $output ) === OBJECT ) { 2435 2494 // Back compat for OBJECT being previously case insensitive. 2436 return $this->last_result[ $y] ? $this->last_result[$y] : null;2495 return $this->last_result[ $y ] ? $this->last_result[ $y ] : null; 2437 2496 } else { 2438 $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N");2497 $this->print_error( ' $db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N' ); 2439 2498 } 2440 2499 } … … 2453 2512 * @return array Database query result. Array indexed from 0 by SQL result row number. 2454 2513 */ 2455 public function get_col( $query = null 2514 public function get_col( $query = null, $x = 0 ) { 2456 2515 if ( $this->check_current_query && $this->check_safe_collation( $query ) ) { 2457 2516 $this->check_current_query = false; … … 2465 2524 // Extract the column values 2466 2525 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 2467 $new_array[ $i] = $this->get_var( null, $x, $i );2526 $new_array[ $i ] = $this->get_var( null, $x, $i ); 2468 2527 } 2469 2528 return $new_array; … … 2507 2566 foreach ( $this->last_result as $row ) { 2508 2567 $var_by_ref = get_object_vars( $row ); 2509 $key = array_shift( $var_by_ref );2510 if ( ! isset( $new_array[ $key ] ) ) 2568 $key = array_shift( $var_by_ref ); 2569 if ( ! isset( $new_array[ $key ] ) ) { 2511 2570 $new_array[ $key ] = $row; 2571 } 2512 2572 } 2513 2573 return $new_array; … … 2567 2627 2568 2628 $table_parts = explode( '.', $table ); 2569 $table = '`' . implode( '`.`', $table_parts ) . '`';2570 $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" );2629 $table = '`' . implode( '`.`', $table_parts ) . '`'; 2630 $results = $this->get_results( "SHOW FULL COLUMNS FROM $table" ); 2571 2631 if ( ! $results ) { 2572 2632 return new WP_Error( 'wpdb_get_table_charset_failure' ); … … 2644 2704 */ 2645 2705 public function get_col_charset( $table, $column ) { 2646 $tablekey = strtolower( $table );2706 $tablekey = strtolower( $table ); 2647 2707 $columnkey = strtolower( $column ); 2648 2708 … … 2709 2769 */ 2710 2770 public function get_col_length( $table, $column ) { 2711 $tablekey = strtolower( $table );2771 $tablekey = strtolower( $table ); 2712 2772 $columnkey = strtolower( $column ); 2713 2773 … … 2738 2798 } 2739 2799 2740 switch ( $type ) {2800 switch ( $type ) { 2741 2801 case 'char': 2742 2802 case 'varchar': … … 2839 2899 2840 2900 $this->checking_collation = true; 2841 $collation = $this->get_table_charset( $table );2901 $collation = $this->get_table_charset( $table ); 2842 2902 $this->checking_collation = false; 2843 2903 … … 2886 2946 2887 2947 if ( is_array( $value['length'] ) ) { 2888 $length = $value['length']['length'];2948 $length = $value['length']['length']; 2889 2949 $truncate_by_byte_length = 'byte' === $value['length']['type']; 2890 2950 } else { … … 2915 2975 ) { 2916 2976 $truncate_by_byte_length = true; 2917 $needs_validation = false;2977 $needs_validation = false; 2918 2978 } 2919 2979 … … 2949 3009 } 2950 3010 2951 $regex .= '){1,40} # ...one or more times3011 $regex .= '){1,40} # ...one or more times 2952 3012 ) 2953 3013 | . # anything else 2954 3014 /x'; 2955 3015 $value['value'] = preg_replace( $regex, '$1', $value['value'] ); 2956 2957 3016 2958 3017 if ( false !== $length && mb_strlen( $value['value'], 'UTF-8' ) > $length ) { … … 2990 3049 2991 3050 if ( is_array( $value['length'] ) ) { 2992 $length = sprintf( '%.0f', $value['length']['length'] );3051 $length = sprintf( '%.0f', $value['length']['length'] ); 2993 3052 $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), $length ) USING $connection_charset )", $value['value'] ); 2994 } else 3053 } elseif ( 'binary' !== $charset ) { 2995 3054 // If we don't have a length, there's no need to convert binary - it will always return the same result. 2996 3055 $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] ); … … 3011 3070 3012 3071 $this->check_current_query = false; 3013 $row = $this->get_row( "SELECT ". implode( ', ', $sql ), ARRAY_A );3072 $row = $this->get_row( 'SELECT ' . implode( ', ', $sql ), ARRAY_A ); 3014 3073 if ( ! $row ) { 3015 3074 return new WP_Error( 'wpdb_strip_invalid_text_failure' ); … … 3017 3076 3018 3077 foreach ( array_keys( $data ) as $column ) { 3019 if ( isset( $row[ "x_$column"] ) ) {3020 $data[ $column ]['value'] = $row[ "x_$column"];3078 if ( isset( $row[ "x_$column" ] ) ) { 3079 $data[ $column ]['value'] = $row[ "x_$column" ]; 3021 3080 } 3022 3081 } … … 3100 3159 'charset' => $charset, 3101 3160 'length' => $this->get_col_length( $table, $column ), 3102 ) 3161 ), 3103 3162 ); 3104 3163 … … 3130 3189 3131 3190 // Quickly match most common queries. 3132 if ( preg_match( '/^\s*(?:' 3191 if ( preg_match( 3192 '/^\s*(?:' 3133 3193 . 'SELECT.*?\s+FROM' 3134 3194 . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' … … 3136 3196 . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' 3137 3197 . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:.+?FROM)?' 3138 . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe ) ) { 3198 . ')\s+((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)/is', $query, $maybe 3199 ) ) { 3139 3200 return str_replace( '`', '', $maybe[1] ); 3140 3201 } … … 3155 3216 3156 3217 // Big pattern for the rest of the table-related queries. 3157 if ( preg_match( '/^\s*(?:' 3218 if ( preg_match( 3219 '/^\s*(?:' 3158 3220 . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM' 3159 3221 . '|DESCRIBE|DESC|EXPLAIN|HANDLER' … … 3169 3231 . '|(?:GRANT|REVOKE).*ON\s+TABLE' 3170 3232 . '|SHOW\s+(?:.*FROM|.*TABLE)' 3171 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe ) ) { 3233 . ')\s+\(*\s*((?:[0-9a-zA-Z$_.`-]|[\xC2-\xDF][\x80-\xBF])+)\s*\)*/is', $query, $maybe 3234 ) ) { 3172 3235 return str_replace( '`', '', $maybe[1] ); 3173 3236 } … … 3180 3243 * 3181 3244 * @since 3.5.0 3182 *3183 3245 */ 3184 3246 protected function load_col_info() { 3185 if ( $this->col_info ) 3247 if ( $this->col_info ) { 3186 3248 return; 3249 } 3187 3250 3188 3251 if ( $this->use_mysqli ) { … … 3213 3276 if ( $this->col_info ) { 3214 3277 if ( $col_offset == -1 ) { 3215 $i = 0;3278 $i = 0; 3216 3279 $new_array = array(); 3217 3280 foreach ( (array) $this->col_info as $col ) { 3218 $new_array[ $i] = $col->{$info_type};3281 $new_array[ $i ] = $col->{$info_type}; 3219 3282 $i++; 3220 3283 } 3221 3284 return $new_array; 3222 3285 } else { 3223 return $this->col_info[ $col_offset]->{$info_type};3286 return $this->col_info[ $col_offset ]->{$info_type}; 3224 3287 } 3225 3288 } … … 3261 3324 */ 3262 3325 public function bail( $message, $error_code = '500' ) { 3263 if ( ! $this->show_errors ) {3326 if ( ! $this->show_errors ) { 3264 3327 if ( class_exists( 'WP_Error', false ) ) { 3265 $this->error = new WP_Error( $error_code, $message);3328 $this->error = new WP_Error( $error_code, $message ); 3266 3329 } else { 3267 3330 $this->error = $message; … … 3269 3332 return false; 3270 3333 } 3271 wp_die( $message);3334 wp_die( $message ); 3272 3335 } 3273 3336 … … 3293 3356 3294 3357 if ( $closed ) { 3295 $this->dbh = null;3296 $this->ready = false;3358 $this->dbh = null; 3359 $this->ready = false; 3297 3360 $this->has_connected = false; 3298 3361 } … … 3314 3377 global $wp_version, $required_mysql_version; 3315 3378 // Make sure the server has the required MySQL version 3316 if ( version_compare( $this->db_version(), $required_mysql_version, '<') ) {3379 if ( version_compare( $this->db_version(), $required_mysql_version, '<' ) ) { 3317 3380 /* translators: 1: WordPress version number, 2: Minimum required MySQL version number */ 3318 return new WP_Error( 'database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ));3381 return new WP_Error( 'database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ) ); 3319 3382 } 3320 3383 } … … 3347 3410 $charset_collate = ''; 3348 3411 3349 if ( ! empty( $this->charset ) ) 3412 if ( ! empty( $this->charset ) ) { 3350 3413 $charset_collate = "DEFAULT CHARACTER SET $this->charset"; 3351 if ( ! empty( $this->collate ) ) 3414 } 3415 if ( ! empty( $this->collate ) ) { 3352 3416 $charset_collate .= " COLLATE $this->collate"; 3417 } 3353 3418 3354 3419 return $charset_collate; … … 3373 3438 3374 3439 switch ( strtolower( $db_cap ) ) { 3375 case 'collation' 3376 case 'group_concat' 3377 case 'subqueries' 3440 case 'collation': // @since 2.5.0 3441 case 'group_concat': // @since 2.7.0 3442 case 'subqueries': // @since 2.7.0 3378 3443 return version_compare( $version, '4.1', '>=' ); 3379 case 'set_charset' 3444 case 'set_charset': 3380 3445 return version_compare( $version, '5.0.7', '>=' ); 3381 case 'utf8mb4' 3446 case 'utf8mb4': // @since 4.1.0 3382 3447 if ( version_compare( $version, '5.5.3', '<' ) ) { 3383 3448 return false; … … 3399 3464 return version_compare( $client_version, '5.5.3', '>=' ); 3400 3465 } 3401 case 'utf8mb4_520' 3466 case 'utf8mb4_520': // @since 4.6.0 3402 3467 return version_compare( $version, '5.6', '>=' ); 3403 3468 }
Note: See TracChangeset
for help on using the changeset viewer.