Ticket #16764: 16764.2.patch
| File 16764.2.patch, 27.5 KB (added by hakre, 2 years ago) |
|---|
-
wp-includes/wp-db.php
35 35 define( 'ARRAY_N', 'ARRAY_N' ); 36 36 37 37 /** 38 * WordPress Database Access Abstraction Object Methods 39 * 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 /** 38 70 * WordPress Database Access Abstraction Object 39 71 * 40 72 * It is possible to replace this class with your own 41 73 * 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. 74 * file with your class. You can not name it wpdb, because this 75 * file will be included. 45 76 * 46 77 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 47 78 * … … 49 80 * @subpackage Database 50 81 * @since 0.71 51 82 */ 52 class wpdb { 83 class wpdb implements WP_Db_Methods { 84 85 /* 86 * private variables {@todo two execptions: $prefix and $base_prefix}} 87 */ 53 88 54 89 /** 55 90 * Whether to show SQL/DB errors … … 58 93 * @access private 59 94 * @var bool 60 95 */ 61 var$show_errors = false;96 private $show_errors = false; 62 97 63 98 /** 64 99 * Whether to suppress errors during the DB bootstrapping. … … 67 102 * @since 2.5.0 68 103 * @var bool 69 104 */ 70 var$suppress_errors = false;105 private $suppress_errors = false; 71 106 72 107 /** 73 108 * The last error during query. … … 77 112 * @access private 78 113 * @var string 79 114 */ 80 var$last_error = '';115 private $last_error = ''; 81 116 82 117 /** 83 118 * Amount of queries made … … 86 121 * @access private 87 122 * @var int 88 123 */ 89 var$num_queries = 0;124 private $num_queries = 0; 90 125 91 126 /** 92 127 * Count of rows returned by previous query … … 95 130 * @access private 96 131 * @var int 97 132 */ 98 var$num_rows = 0;133 private $num_rows = 0; 99 134 100 135 /** 101 136 * Count of affected rows by previous query … … 104 139 * @access private 105 140 * @var int 106 141 */ 107 var$rows_affected = 0;142 private $rows_affected = 0; 108 143 109 144 /** 110 * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).111 *112 * @since 0.71113 * @access public114 * @var int115 */116 var $insert_id = 0;117 118 /**119 145 * Saved result of the last query made 120 146 * 121 147 * @since 1.2.0 122 148 * @access private 123 149 * @var array 124 150 */ 125 var$last_query;151 private $last_query; 126 152 127 153 /** 128 154 * Results of the last query made … … 131 157 * @access private 132 158 * @var array|null 133 159 */ 134 var$last_result;160 private $last_result; 135 161 136 162 /** 137 163 * Saved info on the table column … … 140 166 * @access private 141 167 * @var array 142 168 */ 143 var$col_info;169 private $col_info; 144 170 145 171 /** 146 172 * Saved queries that were executed … … 149 175 * @access private 150 176 * @var array 151 177 */ 152 var$queries;178 private $queries; 153 179 154 180 /** 181 * Timer start value, for debugging purposes. 182 * 183 * @since 1.5.0 184 * @access private 185 * @var float 186 * @see timer_stop() 187 * @see timer_start() 188 */ 189 private $time_start; 190 191 /** 155 192 * WordPress table prefix 156 193 * 157 194 * You can set this to have multiple WordPress installations 158 195 * in a single database. The second reason is for possible 159 196 * security precautions. 160 197 * 198 * @todo see Ticket #16756 {@link http://core.trac.wordpress.org/attachment/ticket/16756}} 199 * 161 200 * @since 0.71 162 201 * @access private 163 202 * @var string 164 203 */ 165 var$prefix = '';204 public $prefix = ''; 166 205 167 206 /** 168 207 * Whether the database queries are ready to start executing. … … 171 210 * @access private 172 211 * @var bool 173 212 */ 174 var$ready = false;213 private $ready = false; 175 214 176 215 /** 177 * {@internal Missing Description}}178 *179 * @since 3.0.0180 * @access public181 * @var int182 */183 var $blogid = 0;184 185 /**186 * {@internal Missing Description}}187 *188 * @since 3.0.0189 * @access public190 * @var int191 */192 var $siteid = 0;193 194 /**195 216 * List of WordPress per-blog tables 196 217 * 197 218 * @since 2.5.0 … … 199 220 * @see wpdb::tables() 200 221 * @var array 201 222 */ 202 var$tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',223 private $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 203 224 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 204 225 205 226 /** … … 212 233 * @see wpdb::tables() 213 234 * @var array 214 235 */ 215 var$old_tables = array( 'categories', 'post2cat', 'link2cat' );236 private $old_tables = array( 'categories', 'post2cat', 'link2cat' ); 216 237 217 238 /** 218 239 * List of WordPress global tables … … 222 243 * @see wpdb::tables() 223 244 * @var array 224 245 */ 225 var$global_tables = array( 'users', 'usermeta' );246 private $global_tables = array( 'users', 'usermeta' ); 226 247 227 248 /** 228 249 * List of Multisite global tables … … 232 253 * @see wpdb::tables() 233 254 * @var array 234 255 */ 235 var$ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',256 private $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 236 257 'sitecategories', 'registration_log', 'blog_versions' ); 237 258 238 259 /** 260 * Database Username 261 * 262 * @since 2.9.0 263 * @access private 264 * @var string 265 */ 266 private $dbuser; 267 268 /* 269 * public variables 270 */ 271 272 /** 273 * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). 274 * 275 * @since 0.71 276 * @access public 277 * @var int 278 */ 279 public $insert_id = 0; 280 281 /** 282 * {@internal Missing Description}} 283 * 284 * @since 3.0.0 285 * @access public 286 * @var int 287 */ 288 public $blogid = 0; 289 290 /** 291 * {@internal Missing Description}} 292 * 293 * @since 3.0.0 294 * @access public 295 * @var int 296 */ 297 public $siteid = 0; 298 299 /** 239 300 * WordPress Comments table 240 301 * 241 302 * @since 1.5.0 242 303 * @access public 243 304 * @var string 244 305 */ 245 var$comments;306 public $comments; 246 307 247 308 /** 248 309 * WordPress Comment Metadata table … … 251 312 * @access public 252 313 * @var string 253 314 */ 254 var$commentmeta;315 public $commentmeta; 255 316 256 317 /** 257 318 * WordPress Links table … … 260 321 * @access public 261 322 * @var string 262 323 */ 263 var$links;324 public $links; 264 325 265 326 /** 266 327 * WordPress Options table … … 269 330 * @access public 270 331 * @var string 271 332 */ 272 var$options;333 public $options; 273 334 274 335 /** 275 336 * WordPress Post Metadata table … … 278 339 * @access public 279 340 * @var string 280 341 */ 281 var$postmeta;342 public $postmeta; 282 343 283 344 /** 284 345 * WordPress Posts table … … 287 348 * @access public 288 349 * @var string 289 350 */ 290 var$posts;351 public $posts; 291 352 292 353 /** 293 354 * WordPress Terms table … … 296 357 * @access public 297 358 * @var string 298 359 */ 299 var$terms;360 public $terms; 300 361 301 362 /** 302 363 * WordPress Term Relationships table … … 305 366 * @access public 306 367 * @var string 307 368 */ 308 var$term_relationships;369 public $term_relationships; 309 370 310 371 /** 311 372 * WordPress Term Taxonomy table … … 314 375 * @access public 315 376 * @var string 316 377 */ 317 var$term_taxonomy;378 public $term_taxonomy; 318 379 319 380 /* 320 381 * Global and Multisite tables … … 327 388 * @access public 328 389 * @var string 329 390 */ 330 var$usermeta;391 public $usermeta; 331 392 332 393 /** 333 394 * WordPress Users table … … 336 397 * @access public 337 398 * @var string 338 399 */ 339 var$users;400 public $users; 340 401 341 402 /** 342 403 * Multisite Blogs table … … 345 406 * @access public 346 407 * @var string 347 408 */ 348 var$blogs;409 public $blogs; 349 410 350 411 /** 351 412 * Multisite Blog Versions table … … 354 415 * @access public 355 416 * @var string 356 417 */ 357 var$blog_versions;418 public $blog_versions; 358 419 359 420 /** 360 421 * Multisite Registration Log table … … 363 424 * @access public 364 425 * @var string 365 426 */ 366 var$registration_log;427 public $registration_log; 367 428 368 429 /** 369 430 * Multisite Signups table … … 372 433 * @access public 373 434 * @var string 374 435 */ 375 var$signups;436 public $signups; 376 437 377 438 /** 378 439 * Multisite Sites table … … 381 442 * @access public 382 443 * @var string 383 444 */ 384 var$site;445 public $site; 385 446 386 447 /** 387 448 * Multisite Sitewide Terms table … … 390 451 * @access public 391 452 * @var string 392 453 */ 393 var$sitecategories;454 public $sitecategories; 394 455 395 456 /** 396 457 * Multisite Site Metadata table … … 399 460 * @access public 400 461 * @var string 401 462 */ 402 var$sitemeta;463 public $sitemeta; 403 464 404 465 /** 405 466 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load. … … 414 475 * @access public 415 476 * @var array 416 477 */ 417 var$field_types = array();478 public $field_types = array(); 418 479 419 480 /** 420 481 * Database table columns charset … … 423 484 * @access public 424 485 * @var string 425 486 */ 426 var$charset;487 public $charset; 427 488 428 489 /** 429 490 * Database table columns collate … … 432 493 * @access public 433 494 * @var string 434 495 */ 435 var$collate;496 public $collate; 436 497 437 498 /** 438 499 * Whether to use mysql_real_escape_string … … 441 502 * @access public 442 503 * @var bool 443 504 */ 444 var$real_escape = false;505 public $real_escape = false; 445 506 446 507 /** 447 * Database Username448 *449 * @since 2.9.0450 * @access private451 * @var string452 */453 var $dbuser;454 455 /**456 508 * A textual description of the last query/get_row/get_var call 457 509 * 458 510 * @since 3.0.0 459 511 * @access public 460 512 * @var string 461 513 */ 462 var$func_call;514 public $func_call; 463 515 464 516 /** 465 517 * Connects to the database server and selects a database 466 518 * 467 * PHP4 compatibility layer for calling the PHP5 constructor. 468 * 469 * @uses wpdb::__construct() Passes parameters and returns result 470 * @since 0.71 471 * 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 476 */ 477 function wpdb( $dbuser, $dbpassword, $dbname, $dbhost ) { 478 return $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost ); 479 } 480 481 /** 482 * Connects to the database server and selects a database 483 * 484 * PHP5 style constructor for compatibility with PHP5. Does 485 * the actual setting up of the class properties and connection 519 * The actual setting up of the class properties and connection 486 520 * to the database. 487 521 * 488 522 * @link http://core.trac.wordpress.org/ticket/3354 … … 493 527 * @param string $dbname MySQL database name 494 528 * @param string $dbhost MySQL database host 495 529 */ 496 function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {497 register_shutdown_function( array( &$this, '__destruct' ) );530 public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 531 register_shutdown_function( array( $this, '__destruct' ) ); 498 532 499 if ( WP_DEBUG )500 $this->show_errors();501 502 533 $this->init_charset(); 503 534 504 535 $this->dbuser = $dbuser; … … 510 541 } 511 542 512 543 /** 513 * PHP5 style destructor andwill run when database object is destroyed.544 * Destructor that will run when database object is destroyed. 514 545 * 546 * Callback of register_shutdown_function 547 * 515 548 * @see wpdb::__construct() 516 549 * @since 2.0.8 517 550 * @return bool true 518 551 */ 519 function __destruct() {552 public function __destruct() { 520 553 return true; 521 554 } 522 555 … … 525 558 * 526 559 * @since 3.1.0 527 560 */ 528 function init_charset() {561 private function init_charset() { 529 562 if ( function_exists('is_multisite') && is_multisite() ) { 530 563 $this->charset = 'utf8'; 531 564 if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) … … 549 582 * @param string $charset The character set (optional) 550 583 * @param string $collate The collation (optional) 551 584 */ 552 function set_charset($dbh, $charset = null, $collate = null) {585 private function set_charset($dbh, $charset = null, $collate = null) { 553 586 if ( !isset($charset) ) 554 587 $charset = $this->charset; 555 588 if ( !isset($collate) ) … … 575 608 * @param string $prefix Alphanumeric name for the new prefix. 576 609 * @return string|WP_Error Old prefix or WP_Error on error 577 610 */ 578 function set_prefix( $prefix, $set_table_names = true ) {611 public function set_prefix( $prefix, $set_table_names = true ) { 579 612 580 613 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 581 614 return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/); … … 614 647 * @param int $site_id Optional. 615 648 * @return string previous blog id 616 649 */ 617 function set_blog_id( $blog_id, $site_id = 0 ) {650 public function set_blog_id( $blog_id, $site_id = 0 ) { 618 651 if ( ! empty( $site_id ) ) 619 652 $this->siteid = $site_id; 620 653 … … 640 673 * @param int $blog_id Optional. 641 674 * @return string Blog prefix. 642 675 */ 643 function get_blog_prefix( $blog_id = null ) {676 public function get_blog_prefix( $blog_id = null ) { 644 677 if ( is_multisite() ) { 645 678 if ( null === $blog_id ) 646 679 $blog_id = $this->blogid; … … 681 714 * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. 682 715 * @return array Table names. When a prefix is requested, the key is the unprefixed table name. 683 716 */ 684 function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {717 public function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { 685 718 switch ( $scope ) { 686 719 case 'all' : 687 720 $tables = array_merge( $this->global_tables, $this->tables ); … … 743 776 * @param resource $dbh Optional link identifier. 744 777 * @return null Always null. 745 778 */ 746 function select( $db, $dbh = null) {779 private function select( $db, $dbh = null) { 747 780 if ( is_null($dbh) ) 748 781 $dbh = $this->dbh; 749 782 … … 771 804 * @param string $string 772 805 * @return string 773 806 */ 774 function _weak_escape( $string ) {807 private function _weak_escape( $string ) { 775 808 return addslashes( $string ); 776 809 } 777 810 … … 786 819 * @param string $string to escape 787 820 * @return string escaped 788 821 */ 789 function _real_escape( $string ) {822 private function _real_escape( $string ) { 790 823 if ( $this->dbh && $this->real_escape ) 791 824 return mysql_real_escape_string( $string, $this->dbh ); 792 825 else … … 804 837 * @param string|array $data 805 838 * @return string|array escaped 806 839 */ 807 function _escape( $data ) {840 private function _escape( $data ) { 808 841 if ( is_array( $data ) ) { 809 842 foreach ( (array) $data as $k => $v ) { 810 843 if ( is_array($v) ) … … 828 861 * @param string|array $data to escape 829 862 * @return string|array escaped as query safe string 830 863 */ 831 function escape( $data ) {864 public function escape( $data ) { 832 865 if ( is_array( $data ) ) { 833 866 foreach ( (array) $data as $k => $v ) { 834 867 if ( is_array( $v ) ) … … 851 884 * @param string $string to escape 852 885 * @return void 853 886 */ 854 function escape_by_ref( &$string ) {887 public function escape_by_ref( &$string ) { 855 888 $string = $this->_real_escape( $string ); 856 889 } 857 890 … … 891 924 * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string 892 925 * if there was something to prepare 893 926 */ 894 function prepare( $query = null ) { // ( $query, *$args )927 public function prepare( $query = null ) { // ( $query, *$args ) 895 928 if ( is_null( $query ) ) 896 929 return; 897 930 … … 916 949 * @param string $str The error to display 917 950 * @return bool False if the showing of errors is disabled. 918 951 */ 919 function print_error( $str = '' ) {952 private function print_error( $str = '' ) { 920 953 global $EZSQL_ERROR; 921 954 922 955 if ( !$str ) … … 973 1006 * @param bool $show Whether to show or hide errors 974 1007 * @return bool Old value for showing errors. 975 1008 */ 976 function show_errors( $show = true ) {1009 public function show_errors( $show = true ) { 977 1010 $errors = $this->show_errors; 978 1011 $this->show_errors = $show; 979 1012 return $errors; … … 989 1022 * 990 1023 * @return bool Whether showing of errors was active 991 1024 */ 992 function hide_errors() {1025 public function hide_errors() { 993 1026 $show = $this->show_errors; 994 1027 $this->show_errors = false; 995 1028 return $show; … … 1006 1039 * @param bool $suppress Optional. New value. Defaults to true. 1007 1040 * @return bool Old value 1008 1041 */ 1009 function suppress_errors( $suppress = true ) {1042 public function suppress_errors( $suppress = true ) { 1010 1043 $errors = $this->suppress_errors; 1011 1044 $this->suppress_errors = (bool) $suppress; 1012 1045 return $errors; … … 1018 1051 * @since 0.71 1019 1052 * @return void 1020 1053 */ 1021 function flush() {1054 private function flush() { 1022 1055 $this->last_result = array(); 1023 1056 $this->col_info = null; 1024 1057 $this->last_query = null; … … 1029 1062 * 1030 1063 * @since 3.0.0 1031 1064 */ 1032 function db_connect() { 1033 global $db_list, $global_db_list; 1034 1065 private function db_connect() { 1035 1066 if ( WP_DEBUG ) { 1036 1067 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 1037 1068 } else { … … 1075 1106 * @param string $query Database query 1076 1107 * @return int|false Number of rows affected/selected or false on error 1077 1108 */ 1078 function query( $query ) {1109 public function query( $query ) { 1079 1110 if ( ! $this->ready ) 1080 1111 return false; 1081 1112 … … 1157 1188 * 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 1189 * @return int|false The number of rows inserted, or false on error. 1159 1190 */ 1160 function insert( $table, $data, $format = null ) {1191 public function insert( $table, $data, $format = null ) { 1161 1192 return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); 1162 1193 } 1163 1194 … … 1180 1211 * 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 1212 * @return int|false The number of rows affected, or false on error. 1182 1213 */ 1183 function replace( $table, $data, $format = null ) {1214 public function replace( $table, $data, $format = null ) { 1184 1215 return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); 1185 1216 } 1186 1217 … … 1201 1232 * 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 1233 * @return int|false The number of rows affected, or false on error. 1203 1234 */ 1204 function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {1235 private function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { 1205 1236 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) 1206 1237 return false; 1207 1238 $formats = $format = (array) $format; … … 1241 1272 * @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 1273 * @return int|false The number of rows updated, or false on error. 1243 1274 */ 1244 function update( $table, $data, $where, $format = null, $where_format = null ) {1275 public function update( $table, $data, $where, $format = null, $where_format = null ) { 1245 1276 if ( ! is_array( $data ) || ! is_array( $where ) ) 1246 1277 return false; 1247 1278 … … 1282 1313 * @since 0.71 1283 1314 * 1284 1315 * @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.1316 * @param int $column Optional. Column of value to return. Indexed from 0. 1317 * @param int $row Optional. Row of value to return. Indexed from 0. 1287 1318 * @return string|null Database query result (as string), or null on failure 1288 1319 */ 1289 function get_var( $query = null, $x = 0, $y= 0 ) {1290 $this->func_call = "\$db->get_var(\"$query\", $ x, $y)";1320 public function get_var( $query = null, $column = 0, $row = 0 ) { 1321 $this->func_call = "\$db->get_var(\"$query\", $column, $row)"; 1291 1322 if ( $query ) 1292 1323 $this->query( $query ); 1293 1324 1294 1325 // 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] ) );1326 if ( !empty( $this->last_result[$row] ) ) { 1327 $values = array_values( get_object_vars( $this->last_result[$row] ) ); 1297 1328 } 1298 1329 1299 1330 // If there is a value return it else return null 1300 return ( isset( $values[$ x] ) && $values[$x] !== '' ) ? $values[$x] : null;1331 return ( isset( $values[$column] ) && $values[$column] !== '' ) ? $values[$column] : null; 1301 1332 } 1302 1333 1303 1334 /** … … 1310 1341 * @param string|null $query SQL query. 1311 1342 * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), 1312 1343 * a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 1313 * @param int $ yOptional. Row to return. Indexed from 0.1344 * @param int $row Optional. Row to return. Indexed from 0. 1314 1345 * @return mixed Database query result in format specifed by $output or null on failure 1315 1346 */ 1316 function get_row( $query = null, $output = OBJECT, $y= 0 ) {1317 $this->func_call = "\$db->get_row(\"$query\",$output,$ y)";1347 public function get_row( $query = null, $output = null, $row = 0 ) { 1348 $this->func_call = "\$db->get_row(\"$query\",$output,$row)"; 1318 1349 if ( $query ) 1319 1350 $this->query( $query ); 1320 1351 else 1321 1352 return null; 1322 1353 1323 if ( !isset( $this->last_result[$ y] ) )1354 if ( !isset( $this->last_result[$row] ) ) 1324 1355 return null; 1325 1356 1326 if ( $output == OBJECT ) {1327 return $this->last_result[$ y] ? $this->last_result[$y] : null;1357 if ( null === $output || $output == OBJECT ) { 1358 return $this->last_result[$row] ? $this->last_result[$row] : null; 1328 1359 } elseif ( $output == ARRAY_A ) { 1329 return $this->last_result[$ y] ? get_object_vars( $this->last_result[$y] ) : null;1360 return $this->last_result[$row] ? get_object_vars( $this->last_result[$row] ) : null; 1330 1361 } elseif ( $output == ARRAY_N ) { 1331 return $this->last_result[$ y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;1362 return $this->last_result[$row] ? array_values( get_object_vars( $this->last_result[$row] ) ) : null; 1332 1363 } else { 1333 1364 $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 1365 } … … 1344 1375 * @since 0.71 1345 1376 * 1346 1377 * @param string|null $query Optional. SQL query. Defaults to previous query. 1347 * @param int $ xOptional. Column to return. Indexed from 0.1378 * @param int $column Optional. Column to return. Indexed from 0. 1348 1379 * @return array Database query result. Array indexed from 0 by SQL result row number. 1349 1380 */ 1350 function get_col( $query = null , $x= 0 ) {1381 public function get_col( $query = null , $column = 0 ) { 1351 1382 if ( $query ) 1352 1383 $this->query( $query ); 1353 1384 1354 1385 $new_array = array(); 1355 1386 // Extract the column values 1356 1387 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 1357 $new_array[$i] = $this->get_var( null, $ x, $i );1388 $new_array[$i] = $this->get_var( null, $column, $i ); 1358 1389 } 1359 1390 return $new_array; 1360 1391 } … … 1372 1403 * 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 1404 * @return mixed Database query results 1374 1405 */ 1375 function get_results( $query = null, $output = OBJECT) {1406 public function get_results( $query = null, $output = null ) { 1376 1407 $this->func_call = "\$db->get_results(\"$query\", $output)"; 1377 1408 1378 1409 if ( $query ) … … 1381 1412 return null; 1382 1413 1383 1414 $new_array = array(); 1384 if ( $output == OBJECT ) {1415 if ( $output === null || $output == OBJECT ) { 1385 1416 // Return an integer-keyed array of row objects 1386 1417 return $this->last_result; 1387 1418 } elseif ( $output == OBJECT_K ) { … … 1420 1451 * @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 1452 * @return mixed Column Results 1422 1453 */ 1423 function get_col_info( $info_type = 'name', $col_offset = -1) {1454 public function get_col_info( $info_type = 'name', $col_offset = null ) { 1424 1455 if ( $this->col_info ) { 1425 if ( $col_offset == -1) {1456 if ( $col_offset === null ) { 1426 1457 $i = 0; 1427 1458 $new_array = array(); 1428 1459 foreach( (array) $this->col_info as $col ) { … … 1443 1474 * 1444 1475 * @return true 1445 1476 */ 1446 function timer_start() { 1447 $mtime = explode( ' ', microtime() ); 1448 $this->time_start = $mtime[1] + $mtime[0]; 1477 private function timer_start() { 1478 $this->time_start = microtime( true ); 1449 1479 return true; 1450 1480 } 1451 1481 … … 1456 1486 * 1457 1487 * @return int Total time spent on the query, in milliseconds 1458 1488 */ 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; 1489 private function timer_stop() { 1490 $time_total = microtime( true ) - $this->time_start; 1491 return (int) $time_total; 1464 1492 } 1465 1493 1466 1494 /** … … 1474 1502 * @param string $error_code Optional. A Computer readable string to identify the error. 1475 1503 * @return false|void 1476 1504 */ 1477 function bail( $message, $error_code = '500' ) {1505 private function bail( $message, $error_code = '500' ) { 1478 1506 if ( !$this->show_errors ) { 1479 1507 if ( class_exists( 'WP_Error' ) ) 1480 1508 $this->error = new WP_Error($error_code, $message); … … 1494 1522 * 1495 1523 * @return WP_Error 1496 1524 */ 1497 function check_database_version() {1525 public function check_database_version() { 1498 1526 global $wp_version, $required_mysql_version; 1499 1527 // Make sure the server has the required MySQL version 1500 1528 if ( version_compare($this->db_version(), $required_mysql_version, '<') ) … … 1502 1530 } 1503 1531 1504 1532 /** 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 1533 * Determine if a database supports a particular feature 1519 1534 * 1520 1535 * @since 2.7.0 1521 1536 * @see wpdb::db_version() 1522 1537 * 1523 * @param string $ db_cap thefeature1538 * @param string $feature the database capabilitiy feature 1524 1539 * @return bool 1525 1540 */ 1526 function has_cap( $db_cap) {1541 public function has_cap( $feature ) { 1527 1542 $version = $this->db_version(); 1528 1543 1529 switch ( strtolower( $ db_cap) ) {1544 switch ( strtolower( $feature ) ) { 1530 1545 case 'collation' : // @since 2.5.0 1531 1546 case 'group_concat' : // @since 2.7 1532 1547 case 'subqueries' : // @since 2.7 … … 1548 1563 * 1549 1564 * @return string The name of the calling function 1550 1565 */ 1551 function get_caller() {1566 private function get_caller() { 1552 1567 $trace = array_reverse( debug_backtrace() ); 1553 1568 $caller = array(); 1554 1569 … … 1568 1583 * 1569 1584 * @return false|string false on failure, version number on success 1570 1585 */ 1571 function db_version() {1586 public function db_version() { 1572 1587 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 1573 1588 } 1574 1589 }
