Changeset 13343
- Timestamp:
- 02/23/2010 10:04:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-db.php
r13341 r13343 94 94 * 95 95 * @since 1.2 96 * @access private 96 97 * @var int 97 98 */ … … 102 103 * 103 104 * @since 0.71 105 * @access private 104 106 * @var int 105 107 */ … … 119 121 * 120 122 * @since {@internal Version Unknown}} 121 * @var mixed 123 * @access private 124 * @var array|null 122 125 */ 123 126 var $last_result; … … 167 170 * 168 171 * @since 3.0.0 172 * @access public 169 173 * @var int 170 174 */ … … 175 179 * 176 180 * @since 3.0.0 181 * @access public 177 182 * @var int 178 183 */ 179 184 var $siteid = 0; 180 181 /**182 * WordPress Posts table183 *184 * @since 1.5.0185 * @access public186 * @var string187 */188 var $posts;189 190 /**191 * WordPress Users table192 *193 * @since 1.5.0194 * @access public195 * @var string196 */197 var $users;198 199 /**200 * WordPress Comments table201 *202 * @since 1.5.0203 * @access public204 * @var string205 */206 var $comments;207 208 /**209 * WordPress Links table210 *211 * @since 1.5.0212 * @access public213 * @var string214 */215 var $links;216 217 /**218 * WordPress Options table219 *220 * @since 1.5.0221 * @access public222 * @var string223 */224 var $options;225 226 /**227 * WordPress Post Metadata table228 *229 * @since {@internal Version Unknown}}230 * @access public231 * @var string232 */233 var $postmeta;234 235 /**236 * WordPress Comment Metadata table237 *238 * @since 2.9239 * @access public240 * @var string241 */242 var $commentmeta;243 244 /**245 * WordPress User Metadata table246 *247 * @since 2.3.0248 * @access public249 * @var string250 */251 var $usermeta;252 253 /**254 * WordPress Terms table255 *256 * @since 2.3.0257 * @access public258 * @var string259 */260 var $terms;261 262 /**263 * WordPress Term Taxonomy table264 *265 * @since 2.3.0266 * @access public267 * @var string268 */269 var $term_taxonomy;270 271 /**272 * WordPress Term Relationships table273 *274 * @since 2.3.0275 * @access public276 * @var string277 */278 var $term_relationships;279 185 280 186 /** … … 292 198 * List of deprecated WordPress tables 293 199 * 294 * @deprecated 200 * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539 201 * 295 202 * @since 2.9.0 296 203 * @access private … … 301 208 302 209 /** 303 * Multisite Blogs table304 *305 * @since 3.0.0306 * @access public307 * @var string308 */309 var $blogs;310 311 /**312 * Multisite Signups table313 *314 * @since 3.0.0315 * @access public316 * @var string317 */318 var $signups;319 320 /**321 * Multisite Sites table322 *323 * @since 3.0.0324 * @access public325 * @var string326 */327 var $site;328 329 /**330 * Multisite Site Metadata table331 *332 * @since 3.0.0333 * @access public334 * @var string335 */336 var $sitemeta;337 338 /**339 * Multisite Sitewide Terms table340 *341 * @since 3.0.0342 * @access public343 * @var string344 */345 var $sitecategories;346 347 /**348 * Multisite Registration Log table349 *350 * @since 3.0.0351 * @access public352 * @var string353 */354 var $registration_log;355 356 /**357 * Multisite Blog Versions table358 *359 * @since 3.0.0360 * @access public361 * @var string362 */363 var $blog_versions;364 365 /**366 210 * List of WordPress global tables 367 211 * … … 383 227 var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 384 228 'sitecategories', 'registration_log', 'blog_versions' ); 229 230 /** 231 * WordPress Comments table 232 * 233 * @since 1.5.0 234 * @access public 235 * @var string 236 */ 237 var $comments; 238 239 /** 240 * WordPress Comment Metadata table 241 * 242 * @since 2.9.0 243 * @access public 244 * @var string 245 */ 246 var $commentmeta; 247 248 /** 249 * WordPress Links table 250 * 251 * @since 1.5.0 252 * @access public 253 * @var string 254 */ 255 var $links; 256 257 /** 258 * WordPress Options table 259 * 260 * @since 1.5.0 261 * @access public 262 * @var string 263 */ 264 var $options; 265 266 /** 267 * WordPress Post Metadata table 268 * 269 * @since {@internal Version Unknown}} 270 * @access public 271 * @var string 272 */ 273 var $postmeta; 274 275 /** 276 * WordPress Posts table 277 * 278 * @since 1.5.0 279 * @access public 280 * @var string 281 */ 282 var $posts; 283 284 /** 285 * WordPress Terms table 286 * 287 * @since 2.3.0 288 * @access public 289 * @var string 290 */ 291 var $terms; 292 293 /** 294 * WordPress Term Relationships table 295 * 296 * @since 2.3.0 297 * @access public 298 * @var string 299 */ 300 var $term_relationships; 301 302 /** 303 * WordPress Term Taxonomy table 304 * 305 * @since 2.3.0 306 * @access public 307 * @var string 308 */ 309 var $term_taxonomy; 310 311 /* 312 * Global and Multisite tables 313 */ 314 315 /** 316 * WordPress User Metadata table 317 * 318 * @since 2.3.0 319 * @access public 320 * @var string 321 */ 322 var $usermeta; 323 324 /** 325 * WordPress Users table 326 * 327 * @since 1.5.0 328 * @access public 329 * @var string 330 */ 331 var $users; 332 333 /** 334 * Multisite Blogs table 335 * 336 * @since 3.0.0 337 * @access public 338 * @var string 339 */ 340 var $blogs; 341 342 /** 343 * Multisite Blog Versions table 344 * 345 * @since 3.0.0 346 * @access public 347 * @var string 348 */ 349 var $blog_versions; 350 351 /** 352 * Multisite Registration Log table 353 * 354 * @since 3.0.0 355 * @access public 356 * @var string 357 */ 358 var $registration_log; 359 360 /** 361 * Multisite Signups table 362 * 363 * @since 3.0.0 364 * @access public 365 * @var string 366 */ 367 var $signups; 368 369 /** 370 * Multisite Sites table 371 * 372 * @since 3.0.0 373 * @access public 374 * @var string 375 */ 376 var $site; 377 378 /** 379 * Multisite Sitewide Terms table 380 * 381 * @since 3.0.0 382 * @access public 383 * @var string 384 */ 385 var $sitecategories; 386 387 /** 388 * Multisite Site Metadata table 389 * 390 * @since 3.0.0 391 * @access public 392 * @var string 393 */ 394 var $sitemeta; 385 395 386 396 /** … … 548 558 if ( isset( $this->base_prefix ) ) 549 559 $old_prefix = $this->base_prefix; 560 550 561 $this->base_prefix = $prefix; 562 551 563 foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) 552 564 $this->$table = $prefixed_table; … … 571 583 * @since 3.0.0 572 584 * @access public 573 * @param string$blog_id574 * @param string $site_id.Optional.585 * @param int $blog_id 586 * @param int $site_id Optional. 575 587 * @return string previous blog id 576 588 */ 577 function set_blog_id( $blog_id, $site_id = '') {589 function set_blog_id( $blog_id, $site_id = 0 ) { 578 590 if ( ! empty( $site_id ) ) 579 591 $this->siteid = $site_id; … … 598 610 * @uses is_multisite() 599 611 * @since 3.0.0 600 * @param int $blog_id .Optional.612 * @param int $blog_id Optional. 601 613 * @return string Blog prefix. 602 614 */ 603 615 function get_blog_prefix( $blog_id = 0 ) { 604 616 if ( is_multisite() && $blog_id ) { 605 if ( defined( 'MULTISITE') && ( $blog_id == 0 || $blog_id == 1) )617 if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) 606 618 return $this->base_prefix; 607 619 else … … 620 632 * 621 633 * @since 3.0.0 622 * @uses wpdb:: tables623 * @uses wpdb:: old_tables624 * @uses wpdb:: global_tables625 * @uses wpdb:: ms_global_tables634 * @uses wpdb::$tables 635 * @uses wpdb::$old_tables 636 * @uses wpdb::$global_tables 637 * @uses wpdb::$ms_global_tables 626 638 * @uses is_multisite() 627 639 * 628 * @param string $scope Can be all, global, ms_global, blog, or old tables. Default all. 629 * All returns the blog tables for the queried blog and all global tables. 640 * @param string $scope Can be all, global, ms_global, blog, or old tables. Defaults to all. 641 * 'all' returns 'all' and 'global' tables. No old tables are returned. 642 * 'global' returns the global tables for the installation, returning multisite tables only if running multisite. 643 * 'ms_global' returns the multisite global tables, regardless if current installation is multisite. 644 * 'blog' returns the blog-level tables for the queried blog. 645 * 'old' returns tables which are deprecated. 630 646 * @param bool $prefix Whether to include table prefixes. Default true. If blog 631 * prefix is requested, then the custom users and usermeta tables will be mapped.647 * prefix is requested, then the custom users and usermeta tables will be mapped. 632 648 * @param int $blog_id The blog_id to prefix. Defaults to wpdb::blogid. Used only when prefix is requested. 633 649 * @return array Table names. When a prefix is requested, the key is the unprefixed table name. … … 659 675 if ( ! $blog_id ) 660 676 $blog_id = $this->blogid; 661 $ prefix = $this->get_blog_prefix( $blog_id );677 $blog_prefix = $this->get_blog_prefix( $blog_id ); 662 678 $base_prefix = $this->base_prefix; 663 679 $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); … … 666 682 $tables[ $table ] = $base_prefix . $table; 667 683 else 668 $tables[ $table ] = $ prefix . $table;684 $tables[ $table ] = $blog_prefix . $table; 669 685 unset( $tables[ $k ] ); 670 686 } … … 710 726 * Weak escape 711 727 * 712 * @ seeaddslashes()713 * @since unknown728 * @uses addslashes() 729 * @since {@internal Version Unknown}} 714 730 * @access private 715 731 * … … 724 740 * Real escape 725 741 * 726 * @ seemysql_real_escape_string()727 * @ seeaddslashes()742 * @uses mysql_real_escape_string() 743 * @uses addslashes() 728 744 * @since 2.8 729 745 * @access private … … 740 756 741 757 /** 742 * Escape data. 743 * 744 * @see esc_sql() 758 * Escape data. Works on arrays. 759 * 760 * @uses wpdb::_escape() 761 * @uses wpdb::_real_escape() 745 762 * @since 2.8 746 763 * @access private … … 765 782 766 783 /** 767 * Escapes content for insertion into the database using addslashes(), for security 768 * 769 * @since 0.71 770 * 784 * Escapes content for insertion into the database using addslashes(), for security. 785 * 786 * Works on arrays. 787 * 788 * @since 0.71 771 789 * @param string|array $data to escape 772 790 * @return string|array escaped as query safe string … … 790 808 * Escapes content by reference for insertion into the database, for security 791 809 * 810 * @uses wpdb::_real_escape() 792 811 * @since 2.3.0 793 *794 812 * @param string $string to escape 795 813 * @return void … … 820 838 * 821 839 * <code> 822 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 840 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ) 841 * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); 823 842 * </code> 824 843 * … … 838 857 if ( is_null( $query ) ) 839 858 return; 859 840 860 $args = func_get_args(); 841 861 array_shift( $args ); … … 874 894 $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'WordPress database error %1$s for query %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query); 875 895 876 $log_error = true; 877 if ( ! function_exists('error_log') ) 878 $log_error = false; 879 880 $log_file = @ini_get('error_log'); 881 if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) ) 882 $log_error = false; 883 884 if ( $log_error ) 885 @error_log($error_str, 0); 896 if ( function_exists('error_log') && $log_file = @ini_get('error_log') && ( 'syslog' == $log_file || is_writable( $log_file ) ) ) 897 @error_log( $error_str, 0 ); 886 898 887 899 // Is error output turned on or not.. 888 if ( ! $this->show_errors )900 if ( ! $this->show_errors ) 889 901 return false; 890 902 … … 895 907 error_log( $msg, 3, ERRORLOGFILE ); 896 908 if ( defined( 'DIEONDBERROR' ) ) 897 die( $msg );909 wp_die( $msg ); 898 910 } else { 899 911 $str = htmlspecialchars( $str, ENT_QUOTES ); … … 1022 1034 return false; 1023 1035 1024 // filter the query, if filters are available 1025 // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 1036 // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 1026 1037 if ( function_exists( 'apply_filters' ) ) 1027 1038 $query = apply_filters( 'query', $query ); 1028 1039 1029 // initialize return1030 1040 $return_val = 0; 1031 1041 $this->flush(); … … 1066 1076 1067 1077 $this->result = @mysql_query( $query, $dbh ); 1068 ++$this->num_queries;1069 1070 if ( defined( 'SAVEQUERIES') && SAVEQUERIES )1078 $this->num_queries++; 1079 1080 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1071 1081 $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 1072 1082 … … 1112 1122 * 1113 1123 * <code> 1124 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) 1114 1125 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 1115 1126 * </code> … … 1117 1128 * @since 2.5.0 1118 1129 * @see wpdb::prepare() 1130 * @see wpdb::$field_types 1131 * @see wp_set_wpdb_vars() 1119 1132 * 1120 1133 * @param string $table table name 1121 1134 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1122 * @param array|string $format (optional) An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings. 1135 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. 1136 * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1123 1137 * @return int|false The number of rows inserted, or false on error. 1124 1138 */ … … 1145 1159 * 1146 1160 * <code> 1161 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) ) 1147 1162 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 1148 1163 * </code> … … 1150 1165 * @since 2.5.0 1151 1166 * @see wpdb::prepare() 1167 * @see wpdb::$field_types 1168 * @see wp_set_wpdb_vars() 1152 1169 * 1153 1170 * @param string $table table name 1154 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1155 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw". 1156 * @param array|string $format (optional) An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings. 1157 * @param array|string $format_where (optional) An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $where will be treated as strings. 1171 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1172 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw". 1173 * @param array|string $format Optional. An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data. 1174 * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1175 * @param array|string $format_where Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $where will be treated as strings. 1158 1176 * @return int|false The number of rows updated, or false on error. 1159 1177 */ 1160 1178 function update( $table, $data, $where, $format = null, $where_format = null ) { 1161 if ( ! is_array( $ where ) )1179 if ( ! is_array( $data ) || ! is_array( $where ) ) 1162 1180 return false; 1163 1181 … … 1198 1216 * @since 0.71 1199 1217 * 1200 * @param string|null $query Optional. SQL query. If null (default), usesthe result from the previous query.1201 * @param int $x (optional)Column of value to return. Indexed from 0.1202 * @param int $y (optional)Row of value to return. Indexed from 0.1203 * @return string|null Database query result , or null on failure1218 * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query. 1219 * @param int $x Optional. Column of value to return. Indexed from 0. 1220 * @param int $y Optional. Row of value to return. Indexed from 0. 1221 * @return string|null Database query result (as string), or null on failure 1204 1222 */ 1205 1223 function get_var( $query = null, $x = 0, $y = 0 ) { … … 1225 1243 * 1226 1244 * @param string|null $query SQL query. 1227 * @param string $output (optional) one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 1228 * @param int $y (optional) Row to return. Indexed from 0. 1245 * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), 1246 * a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 1247 * @param int $y Optional. Row to return. Indexed from 0. 1229 1248 * @return mixed Database query result in format specifed by $output or null on failure 1230 1249 */ … … 1259 1278 * @since 0.71 1260 1279 * 1261 * @param string|null $query Optional. SQL query. If null (default), use the result from theprevious query.1280 * @param string|null $query Optional. SQL query. Defaults to previous query. 1262 1281 * @param int $x Optional. Column to return. Indexed from 0. 1263 1282 * @return array Database query result. Array indexed from 0 by SQL result row number. … … 1283 1302 * 1284 1303 * @param string $query SQL query. 1285 * @param string $output (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. With one of the first three, return an array of rows indexed from 0 by SQL result row number. Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively. With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded. 1304 * @param string $output Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. With one of the first three, return an array of rows indexed from 0 by SQL result row number. 1305 * Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively. 1306 * With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded. 1286 1307 * @return mixed Database query results 1287 1308 */ … … 1386 1407 * 1387 1408 * @param string $message The Error message 1388 * @param string $error_code (optional)A Computer readable string to identify the error.1409 * @param string $error_code Optional. A Computer readable string to identify the error. 1389 1410 * @return false|void 1390 1411 */ … … 1437 1458 * @param string $db_cap the feature 1438 1459 * @param false|string|resource $dbh_or_table. Not implemented. 1439 * Which database to test. False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.1440 1460 * @return bool 1441 1461 */ … … 1464 1484 */ 1465 1485 function get_caller() { 1466 $ bt = debug_backtrace();1486 $trace = array_reverse( debug_backtrace() ); 1467 1487 $caller = array(); 1468 1488 1469 $bt = array_reverse( $bt ); 1470 foreach ( (array) $bt as $call ) { 1489 foreach ( $trace as $call ) { 1471 1490 if ( isset( $call['class'] ) && __CLASS__ == $call['class'] ) 1472 continue; 1473 $function = $call['function']; 1474 if ( isset( $call['class'] ) ) 1475 $function = $call['class'] . "->$function"; 1476 $caller[] = $function; 1491 continue; // Filter out wpdb calls. 1477 1492 } 1478 1493 $caller = join( ', ', $caller ); … … 1482 1497 1483 1498 /** 1484 * The database version number 1499 * The database version number. 1500 * 1485 1501 * @param false|string|resource $dbh_or_table. Not implemented. 1486 * Which database to test. False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.1487 1502 * @return false|string false on failure, version number on success 1488 1503 */
Note: See TracChangeset
for help on using the changeset viewer.