Ticket #16764: 16764.patch
File 16764.patch, 38.6 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/deprecated.php
493 493 $this->query_from = " FROM $wpdb->users"; 494 494 $this->query_where = " WHERE 1=1 $search_sql"; 495 495 496 $prefix = $wpdb->get_blog_prefix(); 496 497 if ( $this->role ) { 497 498 $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id"; 498 $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$ wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%');499 $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $this->role . '%'); 499 500 } elseif ( is_multisite() ) { 500 $level_key = $ wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels501 $level_key = $prefix . 'capabilities'; // wpmu site admins don't have user_levels 501 502 $this->query_from .= ", $wpdb->usermeta"; 502 503 $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'"; 503 504 } -
wp-admin/includes/upgrade.php
645 645 } 646 646 647 647 // Obsolete tables 648 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optionvalues'); 649 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiontypes'); 650 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroups'); 651 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'optiongroup_options'); 648 $prefix = $wpdb->get_blog_prefix(); 649 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'optionvalues'); 650 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'optiontypes'); 651 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'optiongroups'); 652 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'optiongroup_options'); 652 653 653 654 // Update comments table to use comment_type 654 655 $wpdb->query("UPDATE $wpdb->comments SET comment_type='trackback', comment_content = REPLACE(comment_content, '<trackback />', '') WHERE comment_content LIKE '<trackback />%'"); … … 689 690 if ( !empty( $user->user_nickname ) ) 690 691 update_user_meta( $user->ID, 'nickname', $wpdb->escape($user->user_nickname) ); 691 692 if ( !empty( $user->user_level ) ) 692 update_user_meta( $user->ID, $wpdb-> prefix. 'user_level', $user->user_level );693 update_user_meta( $user->ID, $wpdb->get_blog_prefix() . 'user_level', $user->user_level ); 693 694 if ( !empty( $user->user_icq ) ) 694 695 update_user_meta( $user->ID, 'icq', $wpdb->escape($user->user_icq) ); 695 696 if ( !empty( $user->user_aim ) ) … … 714 715 endif; 715 716 716 717 // FIXME: RESET_CAPS is temporary code to reset roles and caps if flag is set. 717 $caps = get_user_meta( $user->ID, $wpdb->prefix . 'capabilities'); 718 $prefix = $wpdb->get_blog_prefix(); 719 $caps = get_user_meta( $user->ID, $prefix . 'capabilities'); 718 720 if ( empty($caps) || defined('RESET_CAPS') ) { 719 $level = get_user_meta($user->ID, $ wpdb->prefix . 'user_level', true);721 $level = get_user_meta($user->ID, $prefix . 'user_level', true); 720 722 $role = translate_level_to_role($level); 721 update_user_meta( $user->ID, $ wpdb->prefix . 'capabilities', array($role => true) );723 update_user_meta( $user->ID, $prefix . 'capabilities', array($role => true) ); 722 724 } 723 725 724 726 endforeach; … … 897 899 $link_cat_id_map = array(); 898 900 $default_link_cat = 0; 899 901 $tt_ids = array(); 900 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb-> prefix. 'linkcategories');902 $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM " . $wpdb->get_blog_prefix() . 'linkcategories'); 901 903 foreach ( $link_cats as $category) { 902 904 $cat_id = (int) $category->cat_id; 903 905 $term_id = 0; … … 955 957 956 958 if ( $wp_current_db_version < 4772 ) { 957 959 // Obsolete linkcategories table 958 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb-> prefix. 'linkcategories');960 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->get_blog_prefix() . 'linkcategories'); 959 961 } 960 962 961 963 // Recalculate all counts … … 990 992 */ 991 993 function upgrade_230_old_tables() { 992 994 global $wpdb; 993 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'categories'); 994 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'link2cat'); 995 $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post2cat'); 995 $prefix = $wpdb->get_blog_prefix(); 996 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'categories'); 997 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'link2cat'); 998 $wpdb->query('DROP TABLE IF EXISTS ' . $prefix . 'post2cat'); 996 999 } 997 1000 998 1001 /** -
wp-includes/capabilities.php
98 98 */ 99 99 function _init () { 100 100 global $wpdb, $wp_user_roles; 101 $this->role_key = $wpdb-> prefix. 'user_roles';101 $this->role_key = $wpdb->get_blog_prefix() . 'user_roles'; 102 102 if ( ! empty( $wp_user_roles ) ) { 103 103 $this->roles = $wp_user_roles; 104 104 $this->use_db = false; … … 516 516 function _init_caps( $cap_key = '' ) { 517 517 global $wpdb; 518 518 if ( empty($cap_key) ) 519 $this->cap_key = $wpdb-> prefix. 'capabilities';519 $this->cap_key = $wpdb->get_blog_prefix() . 'capabilities'; 520 520 else 521 521 $this->cap_key = $cap_key; 522 522 $this->caps = &$this->{$this->cap_key}; … … 662 662 function update_user_level_from_caps() { 663 663 global $wpdb; 664 664 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( &$this, 'level_reduction' ), 0 ); 665 update_user_meta( $this->ID, $wpdb-> prefix. 'user_level', $this->user_level );665 update_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level', $this->user_level ); 666 666 } 667 667 668 668 /** … … 704 704 global $wpdb; 705 705 $this->caps = array(); 706 706 delete_user_meta( $this->ID, $this->cap_key ); 707 delete_user_meta( $this->ID, $wpdb-> prefix. 'user_level' );707 delete_user_meta( $this->ID, $wpdb->get_blog_prefix() . 'user_level' ); 708 708 $this->get_role_caps(); 709 709 } 710 710 -
wp-includes/ms-blogs.php
475 475 } 476 476 477 477 $wpdb->set_blog_id($new_blog); 478 $table_prefix = $wpdb-> prefix;478 $table_prefix = $wpdb->get_blog_prefix(); 479 479 $prev_blog_id = $blog_id; 480 480 $blog_id = $new_blog; 481 481 … … 541 541 $wpdb->set_blog_id($blog); 542 542 $prev_blog_id = $blog_id; 543 543 $blog_id = $blog; 544 $table_prefix = $wpdb-> prefix;544 $table_prefix = $wpdb->get_blog_prefix(); 545 545 546 546 if ( is_object( $wp_roles ) ) { 547 547 $wpdb->suppress_errors(); -
wp-includes/user.php
262 262 263 263 // Keys used as object vars cannot have dashes. 264 264 $key = str_replace('-', '', $option); 265 266 if ( isset( $user->{$ wpdb->prefix . $key} ) ) // Blog specific267 $result = $user->{$ wpdb->prefix . $key};265 $prefix = $wpdb->get_blog_prefix(); 266 if ( isset( $user->{$prefix . $key} ) ) // Blog specific 267 $result = $user->{$prefix . $key}; 268 268 elseif ( isset( $user->{$key} ) ) // User specific and cross-blog 269 269 $result = $user->{$key}; 270 270 else … … 295 295 global $wpdb; 296 296 297 297 if ( !$global ) 298 $option_name = $wpdb-> prefix. $option_name;298 $option_name = $wpdb->get_blog_prefix() . $option_name; 299 299 300 300 // For backward compatibility. See differences between update_user_meta() and deprecated update_usermeta(). 301 301 // http://core.trac.wordpress.org/ticket/13088 … … 324 324 global $wpdb; 325 325 326 326 if ( !$global ) 327 $option_name = $wpdb-> prefix. $option_name;327 $option_name = $wpdb->get_blog_prefix() . $option_name; 328 328 return delete_user_meta( $user_id, $option_name ); 329 329 } 330 330 … … 1101 1101 $user->{$key} = $value; 1102 1102 } 1103 1103 1104 $level = $wpdb-> prefix. 'user_level';1104 $level = $wpdb->get_blog_prefix() . 'user_level'; 1105 1105 if ( isset( $user->{$level} ) ) 1106 1106 $user->user_level = $user->{$level}; 1107 1107 -
wp-includes/wp-db.php
35 35 define( 'ARRAY_N', 'ARRAY_N' ); 36 36 37 37 /** 38 * WordPress Database Access Abstraction Object 38 * WordPress Database Access Abstraction Object Methods 39 39 * 40 * It is possible to replace this class with your own 41 * by setting the $wpdb global variable in wp-content/db.php 42 * file with your class. You can name it wpdb also, since 43 * this file will not be included, if the other file is 44 * available. 40 * @package WordPress 41 * @subpackage Database 42 * @since 3.2 43 */ 44 Interface WP_Db_Methods { 45 public function set_prefix( $prefix, $set_table_names = true ); 46 public function set_blog_id( $blog_id, $site_id = 0 ); 47 public function get_blog_prefix( $blog_id = null ); 48 public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ); 49 public function escape( $data ); 50 public function escape_by_ref( &$string ); 51 public function prepare( $query = null ); 52 public function show_errors( $show = true ); 53 public function hide_errors(); 54 public function suppress_errors( $suppress = true ); 55 public function query( $query ); 56 public function insert( $table, $data, $format = null ); 57 public function replace( $table, $data, $format = null ); 58 public function update( $table, $data, $where, $format = null, $where_format = null ); 59 public function get_var( $query = null, $column = 0, $row = 0 ); 60 public function get_row( $query = null, $output = null, $row = 0 ); 61 public function get_col( $query = null , $column = 0 ); 62 public function get_results( $query = null, $output = null ); 63 public function get_col_info( $info_type = 'name', $col_offset = null ); 64 public function has_cap( $feature ); 65 public function db_version(); 66 } 67 68 /** 69 * WordPress Database Access Abstraction Data Object 45 70 * 46 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 71 * All public object variables of the WordPress Database 72 * Acccess Abstraction Object. 47 73 * 48 74 * @package WordPress 49 75 * @subpackage Database 50 * @since 0.7176 * @since 3.2 51 77 */ 52 class wpdb{78 Class WP_Db_Variables { 53 79 54 80 /** 55 * Whether to show SQL/DB errors56 *57 * @since 0.7158 * @access private59 * @var bool60 */61 var $show_errors = false;62 63 /**64 * Whether to suppress errors during the DB bootstrapping.65 *66 * @access private67 * @since 2.5.068 * @var bool69 */70 var $suppress_errors = false;71 72 /**73 * The last error during query.74 *75 * @see get_last_error()76 * @since 2.5.077 * @access private78 * @var string79 */80 var $last_error = '';81 82 /**83 * Amount of queries made84 *85 * @since 1.2.086 * @access private87 * @var int88 */89 var $num_queries = 0;90 91 /**92 * Count of rows returned by previous query93 *94 * @since 1.2.095 * @access private96 * @var int97 */98 var $num_rows = 0;99 100 /**101 * Count of affected rows by previous query102 *103 * @since 0.71104 * @access private105 * @var int106 */107 var $rows_affected = 0;108 109 /**110 81 * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). 111 82 * 112 83 * @since 0.71 113 84 * @access public 114 85 * @var int 115 86 */ 116 var$insert_id = 0;87 public $insert_id = 0; 117 88 118 89 /** 119 * Saved result of the last query made120 *121 * @since 1.2.0122 * @access private123 * @var array124 */125 var $last_query;126 127 /**128 * Results of the last query made129 *130 * @since 1.0.0131 * @access private132 * @var array|null133 */134 var $last_result;135 136 /**137 * Saved info on the table column138 *139 * @since 1.2.0140 * @access private141 * @var array142 */143 var $col_info;144 145 /**146 * Saved queries that were executed147 *148 * @since 1.5.0149 * @access private150 * @var array151 */152 var $queries;153 154 /**155 * WordPress table prefix156 *157 * You can set this to have multiple WordPress installations158 * in a single database. The second reason is for possible159 * security precautions.160 *161 * @since 0.71162 * @access private163 * @var string164 */165 var $prefix = '';166 167 /**168 * Whether the database queries are ready to start executing.169 *170 * @since 2.5.0171 * @access private172 * @var bool173 */174 var $ready = false;175 176 /**177 90 * {@internal Missing Description}} 178 91 * 179 92 * @since 3.0.0 180 93 * @access public 181 94 * @var int 182 95 */ 183 var$blogid = 0;96 public $blogid = 0; 184 97 185 98 /** 186 99 * {@internal Missing Description}} … … 189 102 * @access public 190 103 * @var int 191 104 */ 192 var$siteid = 0;105 public $siteid = 0; 193 106 194 107 /** 195 * List of WordPress per-blog tables196 *197 * @since 2.5.0198 * @access private199 * @see wpdb::tables()200 * @var array201 */202 var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',203 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' );204 205 /**206 * List of deprecated WordPress tables207 *208 * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539209 *210 * @since 2.9.0211 * @access private212 * @see wpdb::tables()213 * @var array214 */215 var $old_tables = array( 'categories', 'post2cat', 'link2cat' );216 217 /**218 * List of WordPress global tables219 *220 * @since 3.0.0221 * @access private222 * @see wpdb::tables()223 * @var array224 */225 var $global_tables = array( 'users', 'usermeta' );226 227 /**228 * List of Multisite global tables229 *230 * @since 3.0.0231 * @access private232 * @see wpdb::tables()233 * @var array234 */235 var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',236 'sitecategories', 'registration_log', 'blog_versions' );237 238 /**239 108 * WordPress Comments table 240 109 * 241 110 * @since 1.5.0 242 111 * @access public 243 112 * @var string 244 113 */ 245 var$comments;114 public $comments; 246 115 247 116 /** 248 117 * WordPress Comment Metadata table … … 251 120 * @access public 252 121 * @var string 253 122 */ 254 var$commentmeta;123 public $commentmeta; 255 124 256 125 /** 257 126 * WordPress Links table … … 260 129 * @access public 261 130 * @var string 262 131 */ 263 var$links;132 public $links; 264 133 265 134 /** 266 135 * WordPress Options table … … 269 138 * @access public 270 139 * @var string 271 140 */ 272 var$options;141 public $options; 273 142 274 143 /** 275 144 * WordPress Post Metadata table … … 278 147 * @access public 279 148 * @var string 280 149 */ 281 var$postmeta;150 public $postmeta; 282 151 283 152 /** 284 153 * WordPress Posts table … … 287 156 * @access public 288 157 * @var string 289 158 */ 290 var$posts;159 public $posts; 291 160 292 161 /** 293 162 * WordPress Terms table … … 296 165 * @access public 297 166 * @var string 298 167 */ 299 var$terms;168 public $terms; 300 169 301 170 /** 302 171 * WordPress Term Relationships table … … 305 174 * @access public 306 175 * @var string 307 176 */ 308 var$term_relationships;177 public $term_relationships; 309 178 310 179 /** 311 180 * WordPress Term Taxonomy table … … 314 183 * @access public 315 184 * @var string 316 185 */ 317 var$term_taxonomy;186 public $term_taxonomy; 318 187 319 188 /* 320 189 * Global and Multisite tables … … 327 196 * @access public 328 197 * @var string 329 198 */ 330 var$usermeta;199 public $usermeta; 331 200 332 201 /** 333 202 * WordPress Users table … … 336 205 * @access public 337 206 * @var string 338 207 */ 339 var$users;208 public $users; 340 209 341 210 /** 342 211 * Multisite Blogs table … … 345 214 * @access public 346 215 * @var string 347 216 */ 348 var$blogs;217 public $blogs; 349 218 350 219 /** 351 220 * Multisite Blog Versions table … … 354 223 * @access public 355 224 * @var string 356 225 */ 357 var$blog_versions;226 public $blog_versions; 358 227 359 228 /** 360 229 * Multisite Registration Log table … … 363 232 * @access public 364 233 * @var string 365 234 */ 366 var$registration_log;235 public $registration_log; 367 236 368 237 /** 369 238 * Multisite Signups table … … 372 241 * @access public 373 242 * @var string 374 243 */ 375 var$signups;244 public $signups; 376 245 377 246 /** 378 247 * Multisite Sites table … … 381 250 * @access public 382 251 * @var string 383 252 */ 384 var$site;253 public $site; 385 254 386 255 /** 387 256 * Multisite Sitewide Terms table … … 390 259 * @access public 391 260 * @var string 392 261 */ 393 var$sitecategories;262 public $sitecategories; 394 263 395 264 /** 396 265 * Multisite Site Metadata table … … 399 268 * @access public 400 269 * @var string 401 270 */ 402 var$sitemeta;271 public $sitemeta; 403 272 404 273 /** 405 274 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load. … … 414 283 * @access public 415 284 * @var array 416 285 */ 417 var$field_types = array();286 public $field_types = array(); 418 287 419 288 /** 420 289 * Database table columns charset … … 423 292 * @access public 424 293 * @var string 425 294 */ 426 var$charset;295 public $charset; 427 296 428 297 /** 429 298 * Database table columns collate … … 432 301 * @access public 433 302 * @var string 434 303 */ 435 var$collate;304 public $collate; 436 305 437 306 /** 438 307 * Whether to use mysql_real_escape_string … … 441 310 * @access public 442 311 * @var bool 443 312 */ 444 var$real_escape = false;313 public $real_escape = false; 445 314 446 315 /** 447 * Database Username316 * A textual description of the last query/get_row/get_var call 448 317 * 449 * @since 2.9.0450 * @access p rivate318 * @since 3.0.0 319 * @access public 451 320 * @var string 452 321 */ 453 var $dbuser; 322 public $func_call; 323 } 454 324 325 /** 326 * WordPress Database Access Abstraction Object Base Class 327 * 328 * It is possible to replace the database abstraction by 329 * extending this abtract class. 330 * 331 * @link http://core.trac.wordpress.org/ticket/3354 332 * 333 * @package WordPress 334 * @subpackage Database 335 * @since 3.2 336 */ 337 abstract class WP_Db_Base extends WP_Db_Variables implements WP_Db_Methods { 338 public function __construct() { 339 register_shutdown_function( array( $this, '__destruct' ) ); 340 } 341 455 342 /** 456 * A textual description of the last query/get_row/get_var call343 * Destructor that will run when database object is destroyed. 457 344 * 458 * @since 3.0.0 459 * @access public 345 * Callback of register_shutdown_function 346 * 347 * @see __construct() 348 * @since 2.0.8 349 * @return bool true 350 */ 351 public function __destruct() { 352 return true; 353 } 354 } 355 356 357 /** 358 * WordPress Database Access Abstraction Object 359 * 360 * It is possible to replace this class with your own 361 * by setting the $wpdb global variable in wp-content/db.php 362 * file with your class. 363 * 364 * You can not name it wpdb, because this file will be included. 365 * 366 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 367 * 368 * @package WordPress 369 * @subpackage Database 370 * @since 0.71 371 */ 372 class wpdb extends WP_Db_Base { 373 374 /** 375 * Whether to show SQL/DB errors 376 * 377 * @since 0.71 378 * @access private 379 * @var bool 380 */ 381 private $show_errors = false; 382 383 /** 384 * Whether to suppress errors during the DB bootstrapping. 385 * 386 * @access private 387 * @since 2.5.0 388 * @var bool 389 */ 390 private $suppress_errors = false; 391 392 /** 393 * The last error during query. 394 * 395 * @see get_last_error() 396 * @since 2.5.0 397 * @access private 460 398 * @var string 461 399 */ 462 var $func_call;400 private $last_error = ''; 463 401 464 402 /** 465 * Connects to the database server and selects a database403 * Amount of queries made 466 404 * 467 * PHP4 compatibility layer for calling the PHP5 constructor. 405 * @since 1.2.0 406 * @access private 407 * @var int 408 */ 409 private $num_queries = 0; 410 411 /** 412 * Count of rows returned by previous query 468 413 * 469 * @uses wpdb::__construct() Passes parameters and returns result 414 * @since 1.2.0 415 * @access private 416 * @var int 417 */ 418 private $num_rows = 0; 419 420 /** 421 * Count of affected rows by previous query 422 * 470 423 * @since 0.71 424 * @access private 425 * @var int 426 */ 427 private $rows_affected = 0; 428 429 /** 430 * Saved result of the last query made 471 431 * 472 * @param string $dbuser MySQL database user 473 * @param string $dbpassword MySQL database password 474 * @param string $dbname MySQL database name 475 * @param string $dbhost MySQL database host 432 * @since 1.2.0 433 * @access private 434 * @var array 476 435 */ 477 function wpdb( $dbuser, $dbpassword, $dbname, $dbhost ) { 478 return $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost ); 479 } 436 private $last_query; 480 437 481 438 /** 439 * Results of the last query made 440 * 441 * @since 1.0.0 442 * @access private 443 * @var array|null 444 */ 445 private $last_result; 446 447 /** 448 * Saved info on the table column 449 * 450 * @since 1.2.0 451 * @access private 452 * @var array 453 */ 454 private $col_info; 455 456 /** 457 * Saved queries that were executed 458 * 459 * @since 1.5.0 460 * @access private 461 * @var array 462 */ 463 private $queries; 464 465 /** 466 * Timer start value, for debugging purposes. 467 * 468 * @since 1.5.0 469 * @access private 470 * @var float 471 * @see timer_stop() 472 * @see timer_start() 473 */ 474 private $time_start; 475 476 /** 477 * WordPress table prefix 478 * 479 * You can set this to have multiple WordPress installations 480 * in a single database. The second reason is for possible 481 * security precautions. 482 * 483 * @since 0.71 484 * @access private 485 * @var string 486 */ 487 private $prefix = ''; 488 489 /** 490 * Whether the database queries are ready to start executing. 491 * 492 * @since 2.5.0 493 * @access private 494 * @var bool 495 */ 496 private $ready = false; 497 498 /** 499 * List of WordPress per-blog tables 500 * 501 * @since 2.5.0 502 * @access private 503 * @see wpdb::tables() 504 * @var array 505 */ 506 private $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 507 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 508 509 /** 510 * List of deprecated WordPress tables 511 * 512 * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539 513 * 514 * @since 2.9.0 515 * @access private 516 * @see wpdb::tables() 517 * @var array 518 */ 519 private $old_tables = array( 'categories', 'post2cat', 'link2cat' ); 520 521 /** 522 * List of WordPress global tables 523 * 524 * @since 3.0.0 525 * @access private 526 * @see wpdb::tables() 527 * @var array 528 */ 529 private $global_tables = array( 'users', 'usermeta' ); 530 531 /** 532 * List of Multisite global tables 533 * 534 * @since 3.0.0 535 * @access private 536 * @see wpdb::tables() 537 * @var array 538 */ 539 private $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 540 'sitecategories', 'registration_log', 'blog_versions' ); 541 542 /** 543 * Database Username 544 * 545 * @since 2.9.0 546 * @access private 547 * @var string 548 */ 549 private $dbuser; 550 551 /** 482 552 * Connects to the database server and selects a database 483 553 * 484 * PHP5 style constructor for compatibility with PHP5.Does554 * Does 485 555 * the actual setting up of the class properties and connection 486 556 * to the database. 487 557 * 488 * @link http://core.trac.wordpress.org/ticket/3354489 558 * @since 2.0.8 490 559 * 491 560 * @param string $dbuser MySQL database user … … 493 562 * @param string $dbname MySQL database name 494 563 * @param string $dbhost MySQL database host 495 564 */ 496 function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {497 register_shutdown_function( array( &$this, '__destruct' ));565 public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 566 parent::__construct(); 498 567 499 if ( WP_DEBUG )500 $this->show_errors();501 502 568 $this->init_charset(); 503 569 504 570 $this->dbuser = $dbuser; … … 510 576 } 511 577 512 578 /** 513 * PHP5 style destructor and will run when database object is destroyed.514 *515 * @see wpdb::__construct()516 * @since 2.0.8517 * @return bool true518 */519 function __destruct() {520 return true;521 }522 523 /**524 579 * Set $this->charset and $this->collate 525 580 * 526 581 * @since 3.1.0 527 582 */ 528 function init_charset() {583 private function init_charset() { 529 584 if ( function_exists('is_multisite') && is_multisite() ) { 530 585 $this->charset = 'utf8'; 531 586 if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) … … 549 604 * @param string $charset The character set (optional) 550 605 * @param string $collate The collation (optional) 551 606 */ 552 function set_charset($dbh, $charset = null, $collate = null) {607 private function set_charset($dbh, $charset = null, $collate = null) { 553 608 if ( !isset($charset) ) 554 609 $charset = $this->charset; 555 610 if ( !isset($collate) ) … … 575 630 * @param string $prefix Alphanumeric name for the new prefix. 576 631 * @return string|WP_Error Old prefix or WP_Error on error 577 632 */ 578 function set_prefix( $prefix, $set_table_names = true ) {633 public function set_prefix( $prefix, $set_table_names = true ) { 579 634 580 635 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 581 636 return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/); … … 614 669 * @param int $site_id Optional. 615 670 * @return string previous blog id 616 671 */ 617 function set_blog_id( $blog_id, $site_id = 0 ) {672 public function set_blog_id( $blog_id, $site_id = 0 ) { 618 673 if ( ! empty( $site_id ) ) 619 674 $this->siteid = $site_id; 620 675 … … 640 695 * @param int $blog_id Optional. 641 696 * @return string Blog prefix. 642 697 */ 643 function get_blog_prefix( $blog_id = null ) {698 public function get_blog_prefix( $blog_id = null ) { 644 699 if ( is_multisite() ) { 645 700 if ( null === $blog_id ) 646 701 $blog_id = $this->blogid; … … 681 736 * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. 682 737 * @return array Table names. When a prefix is requested, the key is the unprefixed table name. 683 738 */ 684 function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {739 public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { 685 740 switch ( $scope ) { 686 741 case 'all' : 687 742 $tables = array_merge( $this->global_tables, $this->tables ); … … 743 798 * @param resource $dbh Optional link identifier. 744 799 * @return null Always null. 745 800 */ 746 function select( $db, $dbh = null) {801 private function select( $db, $dbh = null) { 747 802 if ( is_null($dbh) ) 748 803 $dbh = $this->dbh; 749 804 … … 771 826 * @param string $string 772 827 * @return string 773 828 */ 774 function _weak_escape( $string ) {829 private function _weak_escape( $string ) { 775 830 return addslashes( $string ); 776 831 } 777 832 … … 786 841 * @param string $string to escape 787 842 * @return string escaped 788 843 */ 789 function _real_escape( $string ) {844 private function _real_escape( $string ) { 790 845 if ( $this->dbh && $this->real_escape ) 791 846 return mysql_real_escape_string( $string, $this->dbh ); 792 847 else … … 804 859 * @param string|array $data 805 860 * @return string|array escaped 806 861 */ 807 function _escape( $data ) {862 private function _escape( $data ) { 808 863 if ( is_array( $data ) ) { 809 864 foreach ( (array) $data as $k => $v ) { 810 865 if ( is_array($v) ) … … 828 883 * @param string|array $data to escape 829 884 * @return string|array escaped as query safe string 830 885 */ 831 function escape( $data ) {886 public function escape( $data ) { 832 887 if ( is_array( $data ) ) { 833 888 foreach ( (array) $data as $k => $v ) { 834 889 if ( is_array( $v ) ) … … 851 906 * @param string $string to escape 852 907 * @return void 853 908 */ 854 function escape_by_ref( &$string ) {909 public function escape_by_ref( &$string ) { 855 910 $string = $this->_real_escape( $string ); 856 911 } 857 912 … … 891 946 * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string 892 947 * if there was something to prepare 893 948 */ 894 function prepare( $query = null ) { // ( $query, *$args )949 public function prepare( $query = null ) { // ( $query, *$args ) 895 950 if ( is_null( $query ) ) 896 951 return; 897 952 … … 916 971 * @param string $str The error to display 917 972 * @return bool False if the showing of errors is disabled. 918 973 */ 919 function print_error( $str = '' ) {974 private function print_error( $str = '' ) { 920 975 global $EZSQL_ERROR; 921 976 922 977 if ( !$str ) … … 973 1028 * @param bool $show Whether to show or hide errors 974 1029 * @return bool Old value for showing errors. 975 1030 */ 976 function show_errors( $show = true ) {1031 public function show_errors( $show = true ) { 977 1032 $errors = $this->show_errors; 978 1033 $this->show_errors = $show; 979 1034 return $errors; … … 989 1044 * 990 1045 * @return bool Whether showing of errors was active 991 1046 */ 992 function hide_errors() {1047 public function hide_errors() { 993 1048 $show = $this->show_errors; 994 1049 $this->show_errors = false; 995 1050 return $show; … … 1006 1061 * @param bool $suppress Optional. New value. Defaults to true. 1007 1062 * @return bool Old value 1008 1063 */ 1009 function suppress_errors( $suppress = true ) {1064 public function suppress_errors( $suppress = true ) { 1010 1065 $errors = $this->suppress_errors; 1011 1066 $this->suppress_errors = (bool) $suppress; 1012 1067 return $errors; … … 1018 1073 * @since 0.71 1019 1074 * @return void 1020 1075 */ 1021 function flush() {1076 private function flush() { 1022 1077 $this->last_result = array(); 1023 1078 $this->col_info = null; 1024 1079 $this->last_query = null; … … 1029 1084 * 1030 1085 * @since 3.0.0 1031 1086 */ 1032 function db_connect() { 1033 global $db_list, $global_db_list; 1034 1087 private function db_connect() { 1035 1088 if ( WP_DEBUG ) { 1036 1089 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 1037 1090 } else { … … 1075 1128 * @param string $query Database query 1076 1129 * @return int|false Number of rows affected/selected or false on error 1077 1130 */ 1078 function query( $query ) {1131 public function query( $query ) { 1079 1132 if ( ! $this->ready ) 1080 1133 return false; 1081 1134 … … 1157 1210 * 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. 1158 1211 * @return int|false The number of rows inserted, or false on error. 1159 1212 */ 1160 function insert( $table, $data, $format = null ) {1213 public function insert( $table, $data, $format = null ) { 1161 1214 return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); 1162 1215 } 1163 1216 … … 1180 1233 * 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. 1181 1234 * @return int|false The number of rows affected, or false on error. 1182 1235 */ 1183 function replace( $table, $data, $format = null ) {1236 public function replace( $table, $data, $format = null ) { 1184 1237 return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); 1185 1238 } 1186 1239 … … 1201 1254 * 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. 1202 1255 * @return int|false The number of rows affected, or false on error. 1203 1256 */ 1204 function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {1257 private function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { 1205 1258 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) 1206 1259 return false; 1207 1260 $formats = $format = (array) $format; … … 1241 1294 * @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. 1242 1295 * @return int|false The number of rows updated, or false on error. 1243 1296 */ 1244 function update( $table, $data, $where, $format = null, $where_format = null ) {1297 public function update( $table, $data, $where, $format = null, $where_format = null ) { 1245 1298 if ( ! is_array( $data ) || ! is_array( $where ) ) 1246 1299 return false; 1247 1300 … … 1282 1335 * @since 0.71 1283 1336 * 1284 1337 * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query. 1285 * @param int $ xOptional. Column of value to return. Indexed from 0.1286 * @param int $ yOptional. Row of value to return. Indexed from 0.1338 * @param int $column Optional. Column of value to return. Indexed from 0. 1339 * @param int $row Optional. Row of value to return. Indexed from 0. 1287 1340 * @return string|null Database query result (as string), or null on failure 1288 1341 */ 1289 function get_var( $query = null, $x = 0, $y= 0 ) {1290 $this->func_call = "\$db->get_var(\"$query\", $ x, $y)";1342 public function get_var( $query = null, $column = 0, $row = 0 ) { 1343 $this->func_call = "\$db->get_var(\"$query\", $column, $row)"; 1291 1344 if ( $query ) 1292 1345 $this->query( $query ); 1293 1346 1294 1347 // Extract var out of cached results based x,y vals 1295 if ( !empty( $this->last_result[$ y] ) ) {1296 $values = array_values( get_object_vars( $this->last_result[$ y] ) );1348 if ( !empty( $this->last_result[$row] ) ) { 1349 $values = array_values( get_object_vars( $this->last_result[$row] ) ); 1297 1350 } 1298 1351 1299 1352 // If there is a value return it else return null 1300 return ( isset( $values[$ x] ) && $values[$x] !== '' ) ? $values[$x] : null;1353 return ( isset( $values[$column] ) && $values[$column] !== '' ) ? $values[$column] : null; 1301 1354 } 1302 1355 1303 1356 /** … … 1310 1363 * @param string|null $query SQL query. 1311 1364 * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), 1312 1365 * a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 1313 * @param int $ yOptional. Row to return. Indexed from 0.1366 * @param int $row Optional. Row to return. Indexed from 0. 1314 1367 * @return mixed Database query result in format specifed by $output or null on failure 1315 1368 */ 1316 function get_row( $query = null, $output = OBJECT, $y= 0 ) {1317 $this->func_call = "\$db->get_row(\"$query\",$output,$ y)";1369 public function get_row( $query = null, $output = null, $row = 0 ) { 1370 $this->func_call = "\$db->get_row(\"$query\",$output,$row)"; 1318 1371 if ( $query ) 1319 1372 $this->query( $query ); 1320 1373 else 1321 1374 return null; 1322 1375 1323 if ( !isset( $this->last_result[$ y] ) )1376 if ( !isset( $this->last_result[$row] ) ) 1324 1377 return null; 1325 1378 1326 if ( $output == OBJECT ) {1327 return $this->last_result[$ y] ? $this->last_result[$y] : null;1379 if ( null === $output || $output == OBJECT ) { 1380 return $this->last_result[$row] ? $this->last_result[$row] : null; 1328 1381 } elseif ( $output == ARRAY_A ) { 1329 return $this->last_result[$ y] ? get_object_vars( $this->last_result[$y] ) : null;1382 return $this->last_result[$row] ? get_object_vars( $this->last_result[$row] ) : null; 1330 1383 } elseif ( $output == ARRAY_N ) { 1331 return $this->last_result[$ y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;1384 return $this->last_result[$row] ? array_values( get_object_vars( $this->last_result[$row] ) ) : null; 1332 1385 } else { 1333 1386 $this->print_error(/*WP_I18N_DB_GETROW_ERROR*/" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"/*/WP_I18N_DB_GETROW_ERROR*/); 1334 1387 } … … 1344 1397 * @since 0.71 1345 1398 * 1346 1399 * @param string|null $query Optional. SQL query. Defaults to previous query. 1347 * @param int $ xOptional. Column to return. Indexed from 0.1400 * @param int $column Optional. Column to return. Indexed from 0. 1348 1401 * @return array Database query result. Array indexed from 0 by SQL result row number. 1349 1402 */ 1350 function get_col( $query = null , $x= 0 ) {1403 public function get_col( $query = null , $column = 0 ) { 1351 1404 if ( $query ) 1352 1405 $this->query( $query ); 1353 1406 1354 1407 $new_array = array(); 1355 1408 // Extract the column values 1356 1409 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 1357 $new_array[$i] = $this->get_var( null, $ x, $i );1410 $new_array[$i] = $this->get_var( null, $column, $i ); 1358 1411 } 1359 1412 return $new_array; 1360 1413 } … … 1372 1425 * 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. 1373 1426 * @return mixed Database query results 1374 1427 */ 1375 function get_results( $query = null, $output = OBJECT) {1428 public function get_results( $query = null, $output = null ) { 1376 1429 $this->func_call = "\$db->get_results(\"$query\", $output)"; 1377 1430 1378 1431 if ( $query ) … … 1381 1434 return null; 1382 1435 1383 1436 $new_array = array(); 1384 if ( $output == OBJECT ) {1437 if ( $output === null || $output == OBJECT ) { 1385 1438 // Return an integer-keyed array of row objects 1386 1439 return $this->last_result; 1387 1440 } elseif ( $output == OBJECT_K ) { … … 1420 1473 * @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 1421 1474 * @return mixed Column Results 1422 1475 */ 1423 function get_col_info( $info_type = 'name', $col_offset = -1) {1476 public function get_col_info( $info_type = 'name', $col_offset = null ) { 1424 1477 if ( $this->col_info ) { 1425 if ( $col_offset == -1) {1478 if ( $col_offset === null ) { 1426 1479 $i = 0; 1427 1480 $new_array = array(); 1428 1481 foreach( (array) $this->col_info as $col ) { … … 1443 1496 * 1444 1497 * @return true 1445 1498 */ 1446 function timer_start() { 1447 $mtime = explode( ' ', microtime() ); 1448 $this->time_start = $mtime[1] + $mtime[0]; 1499 private function timer_start() { 1500 $this->time_start = microtime( true ); 1449 1501 return true; 1450 1502 } 1451 1503 … … 1456 1508 * 1457 1509 * @return int Total time spent on the query, in milliseconds 1458 1510 */ 1459 function timer_stop() { 1460 $mtime = explode( ' ', microtime() ); 1461 $time_end = $mtime[1] + $mtime[0]; 1462 $time_total = $time_end - $this->time_start; 1463 return $time_total; 1511 private function timer_stop() { 1512 $time_total = microtime( true ) - $this->time_start; 1513 return (int) $time_total; 1464 1514 } 1465 1515 1466 1516 /** … … 1474 1524 * @param string $error_code Optional. A Computer readable string to identify the error. 1475 1525 * @return false|void 1476 1526 */ 1477 function bail( $message, $error_code = '500' ) {1527 private function bail( $message, $error_code = '500' ) { 1478 1528 if ( !$this->show_errors ) { 1479 1529 if ( class_exists( 'WP_Error' ) ) 1480 1530 $this->error = new WP_Error($error_code, $message); … … 1494 1544 * 1495 1545 * @return WP_Error 1496 1546 */ 1497 function check_database_version() {1547 public function check_database_version() { 1498 1548 global $wp_version, $required_mysql_version; 1499 1549 // Make sure the server has the required MySQL version 1500 1550 if ( version_compare($this->db_version(), $required_mysql_version, '<') ) … … 1502 1552 } 1503 1553 1504 1554 /** 1505 * Whether the database supports collation.1506 *1507 * Called when WordPress is generating the table scheme.1508 *1509 * @since 2.5.01510 *1511 * @return bool True if collation is supported, false if version does not1512 */1513 function supports_collation() {1514 return $this->has_cap( 'collation' );1515 }1516 1517 /**1518 1555 * Determine if a database supports a particular feature 1519 1556 * 1520 1557 * @since 2.7.0 1521 1558 * @see wpdb::db_version() 1522 1559 * 1523 * @param string $ db_cap thefeature1560 * @param string $feature the database capabilitiy feature 1524 1561 * @return bool 1525 1562 */ 1526 function has_cap( $db_cap) {1563 public function has_cap( $feature ) { 1527 1564 $version = $this->db_version(); 1528 1565 1529 switch ( strtolower( $ db_cap) ) {1566 switch ( strtolower( $feature ) ) { 1530 1567 case 'collation' : // @since 2.5.0 1531 1568 case 'group_concat' : // @since 2.7 1532 1569 case 'subqueries' : // @since 2.7 … … 1548 1585 * 1549 1586 * @return string The name of the calling function 1550 1587 */ 1551 function get_caller() {1588 private function get_caller() { 1552 1589 $trace = array_reverse( debug_backtrace() ); 1553 1590 $caller = array(); 1554 1591 … … 1568 1605 * 1569 1606 * @return false|string false on failure, version number on success 1570 1607 */ 1571 function db_version() {1608 public function db_version() { 1572 1609 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 1573 1610 } 1574 1611 }