| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress DB Class 4 * 5 * Original code from {@link http://php.justinvincent.com Justin Vincent (justin@visunet.ie)} 6 * 7 * @package WordPress 8 * @subpackage Database 9 * @since 0.71 10 */ 11 12 /** 13 * @since 0.71 14 */ 15 define( 'EZSQL_VERSION', 'WP1.25' ); 16 17 /** 18 * @since 0.71 19 */ 20 define( 'OBJECT', 'OBJECT', true ); 21 22 /** 23 * @since 2.5.0 24 */ 25 define( 'OBJECT_K', 'OBJECT_K' ); 26 27 /** 28 * @since 0.71 29 */ 30 define( 'ARRAY_A', 'ARRAY_A' ); 31 32 /** 33 * @since 0.71 34 */ 35 define( 'ARRAY_N', 'ARRAY_N' ); 36 37 /** 38 * WordPress Database Access Abstraction Object 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 to your class. The wpdb class will still be included, 43 * so you can extend it or simply use your own. 44 * 45 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class 46 * 47 * @package WordPress 48 * @subpackage Database 49 * @since 0.71 50 */ 51 class wpdb { 52 53 /** 54 * Whether to show SQL/DB errors 55 * 56 * @since 0.71 57 * @access private 58 * @var bool 59 */ 60 var $show_errors = false; 61 62 /** 63 * Whether to suppress errors during the DB bootstrapping. 64 * 65 * @access private 66 * @since 2.5.0 67 * @var bool 68 */ 69 var $suppress_errors = false; 70 71 /** 72 * The last error during query. 73 * 74 * @since 2.5.0 75 * @var string 76 */ 77 var $last_error = ''; 78 79 /** 80 * Amount of queries made 81 * 82 * @since 1.2.0 83 * @access private 84 * @var int 85 */ 86 var $num_queries = 0; 87 88 /** 89 * Count of rows returned by previous query 90 * 91 * @since 1.2.0 92 * @access private 93 * @var int 94 */ 95 var $num_rows = 0; 96 97 /** 98 * Count of affected rows by previous query 99 * 100 * @since 0.71 101 * @access private 102 * @var int 103 */ 104 var $rows_affected = 0; 105 106 /** 107 * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). 108 * 109 * @since 0.71 110 * @access public 111 * @var int 112 */ 113 var $insert_id = 0; 114 115 /** 116 * Saved result of the last query made 117 * 118 * @since 1.2.0 119 * @access private 120 * @var array 121 */ 122 var $last_query; 123 124 /** 125 * Results of the last query made 126 * 127 * @since 1.0.0 128 * @access private 129 * @var array|null 130 */ 131 var $last_result; 132 133 /** 134 * Saved info on the table column 135 * 136 * @since 1.2.0 137 * @access private 138 * @var array 139 */ 140 var $col_info; 141 142 /** 143 * Saved queries that were executed 144 * 145 * @since 1.5.0 146 * @access private 147 * @var array 148 */ 149 var $queries; 150 151 /** 152 * WordPress table prefix 153 * 154 * You can set this to have multiple WordPress installations 155 * in a single database. The second reason is for possible 156 * security precautions. 157 * 158 * @since 0.71 159 * @access private 160 * @var string 161 */ 162 var $prefix = ''; 163 164 /** 165 * Whether the database queries are ready to start executing. 166 * 167 * @since 2.5.0 168 * @access private 169 * @var bool 170 */ 171 var $ready = false; 172 173 /** 174 * {@internal Missing Description}} 175 * 176 * @since 3.0.0 177 * @access public 178 * @var int 179 */ 180 var $blogid = 0; 181 182 /** 183 * {@internal Missing Description}} 184 * 185 * @since 3.0.0 186 * @access public 187 * @var int 188 */ 189 var $siteid = 0; 190 191 /** 192 * List of WordPress per-blog tables 193 * 194 * @since 2.5.0 195 * @access private 196 * @see wpdb::tables() 197 * @var array 198 */ 199 var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta', 200 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' ); 201 202 /** 203 * List of deprecated WordPress tables 204 * 205 * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539 206 * 207 * @since 2.9.0 208 * @access private 209 * @see wpdb::tables() 210 * @var array 211 */ 212 var $old_tables = array( 'categories', 'post2cat', 'link2cat' ); 213 214 /** 215 * List of WordPress global tables 216 * 217 * @since 3.0.0 218 * @access private 219 * @see wpdb::tables() 220 * @var array 221 */ 222 var $global_tables = array( 'users', 'usermeta' ); 223 224 /** 225 * List of Multisite global tables 226 * 227 * @since 3.0.0 228 * @access private 229 * @see wpdb::tables() 230 * @var array 231 */ 232 var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta', 233 'sitecategories', 'registration_log', 'blog_versions' ); 234 235 /** 236 * WordPress Comments table 237 * 238 * @since 1.5.0 239 * @access public 240 * @var string 241 */ 242 var $comments; 243 244 /** 245 * WordPress Comment Metadata table 246 * 247 * @since 2.9.0 248 * @access public 249 * @var string 250 */ 251 var $commentmeta; 252 253 /** 254 * WordPress Links table 255 * 256 * @since 1.5.0 257 * @access public 258 * @var string 259 */ 260 var $links; 261 262 /** 263 * WordPress Options table 264 * 265 * @since 1.5.0 266 * @access public 267 * @var string 268 */ 269 var $options; 270 271 /** 272 * WordPress Post Metadata table 273 * 274 * @since 1.5.0 275 * @access public 276 * @var string 277 */ 278 var $postmeta; 279 280 /** 281 * WordPress Posts table 282 * 283 * @since 1.5.0 284 * @access public 285 * @var string 286 */ 287 var $posts; 288 289 /** 290 * WordPress Terms table 291 * 292 * @since 2.3.0 293 * @access public 294 * @var string 295 */ 296 var $terms; 297 298 /** 299 * WordPress Term Relationships table 300 * 301 * @since 2.3.0 302 * @access public 303 * @var string 304 */ 305 var $term_relationships; 306 307 /** 308 * WordPress Term Taxonomy table 309 * 310 * @since 2.3.0 311 * @access public 312 * @var string 313 */ 314 var $term_taxonomy; 315 316 /* 317 * Global and Multisite tables 318 */ 319 320 /** 321 * WordPress User Metadata table 322 * 323 * @since 2.3.0 324 * @access public 325 * @var string 326 */ 327 var $usermeta; 328 329 /** 330 * WordPress Users table 331 * 332 * @since 1.5.0 333 * @access public 334 * @var string 335 */ 336 var $users; 337 338 /** 339 * Multisite Blogs table 340 * 341 * @since 3.0.0 342 * @access public 343 * @var string 344 */ 345 var $blogs; 346 347 /** 348 * Multisite Blog Versions table 349 * 350 * @since 3.0.0 351 * @access public 352 * @var string 353 */ 354 var $blog_versions; 355 356 /** 357 * Multisite Registration Log table 358 * 359 * @since 3.0.0 360 * @access public 361 * @var string 362 */ 363 var $registration_log; 364 365 /** 366 * Multisite Signups table 367 * 368 * @since 3.0.0 369 * @access public 370 * @var string 371 */ 372 var $signups; 373 374 /** 375 * Multisite Sites table 376 * 377 * @since 3.0.0 378 * @access public 379 * @var string 380 */ 381 var $site; 382 383 /** 384 * Multisite Sitewide Terms table 385 * 386 * @since 3.0.0 387 * @access public 388 * @var string 389 */ 390 var $sitecategories; 391 392 /** 393 * Multisite Site Metadata table 394 * 395 * @since 3.0.0 396 * @access public 397 * @var string 398 */ 399 var $sitemeta; 400 401 /** 402 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load. 403 * 404 * Keys are column names, values are format types: 'ID' => '%d' 405 * 406 * @since 2.8.0 407 * @see wpdb:prepare() 408 * @see wpdb:insert() 409 * @see wpdb:update() 410 * @see wp_set_wpdb_vars() 411 * @access public 412 * @var array 413 */ 414 var $field_types = array(); 415 416 /** 417 * Database table columns charset 418 * 419 * @since 2.2.0 420 * @access public 421 * @var string 422 */ 423 var $charset; 424 425 /** 426 * Database table columns collate 427 * 428 * @since 2.2.0 429 * @access public 430 * @var string 431 */ 432 var $collate; 433 434 /** 435 * Whether to use mysql_real_escape_string 436 * 437 * @since 2.8.0 438 * @access public 439 * @var bool 440 */ 441 var $real_escape = false; 442 443 /** 444 * Database Username 445 * 446 * @since 2.9.0 447 * @access private 448 * @var string 449 */ 450 var $dbuser; 451 452 /** 453 * A textual description of the last query/get_row/get_var call 454 * 455 * @since 3.0.0 456 * @access public 457 * @var string 458 */ 459 var $func_call; 460 461 /** 462 * Whether MySQL is used as the database engine. 463 * 464 * Set in WPDB::db_connect() to true, by default. This is used when checking 465 * against the required MySQL version for WordPress. Normally, a replacement 466 * database drop-in (db.php) will skip these checks, but setting this to true 467 * will force the checks to occur. 468 * 469 * @since 3.3.0 470 * @access public 471 * @var bool 472 */ 473 public $is_mysql = null; 474 475 /** 476 * Connects to the database server and selects a database 477 * 478 * PHP5 style constructor for compatibility with PHP5. Does 479 * the actual setting up of the class properties and connection 480 * to the database. 481 * 482 * @link http://core.trac.wordpress.org/ticket/3354 483 * @since 2.0.8 484 * 485 * @param string $dbuser MySQL database user 486 * @param string $dbpassword MySQL database password 487 * @param string $dbname MySQL database name 488 * @param string $dbhost MySQL database host 489 */ 490 function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { 491 register_shutdown_function( array( &$this, '__destruct' ) ); 492 493 if ( WP_DEBUG ) 494 $this->show_errors(); 495 496 $this->init_charset(); 497 498 $this->dbuser = $dbuser; 499 $this->dbpassword = $dbpassword; 500 $this->dbname = $dbname; 501 $this->dbhost = $dbhost; 502 503 $this->db_connect(); 504 } 505 506 /** 507 * PHP5 style destructor and will run when database object is destroyed. 508 * 509 * @see wpdb::__construct() 510 * @since 2.0.8 511 * @return bool true 512 */ 513 function __destruct() { 514 return true; 515 } 516 517 /** 518 * Set $this->charset and $this->collate 519 * 520 * @since 3.1.0 521 */ 522 function init_charset() { 523 if ( function_exists('is_multisite') && is_multisite() ) { 524 $this->charset = 'utf8'; 525 if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) 526 $this->collate = DB_COLLATE; 527 else 528 $this->collate = 'utf8_general_ci'; 529 } elseif ( defined( 'DB_COLLATE' ) ) { 530 $this->collate = DB_COLLATE; 531 } 532 533 if ( defined( 'DB_CHARSET' ) ) 534 $this->charset = DB_CHARSET; 535 } 536 537 /** 538 * Sets the connection's character set. 539 * 540 * @since 3.1.0 541 * 542 * @param resource $dbh The resource given by mysql_connect 543 * @param string $charset The character set (optional) 544 * @param string $collate The collation (optional) 545 */ 546 function set_charset($dbh, $charset = null, $collate = null) { 547 if ( !isset($charset) ) 548 $charset = $this->charset; 549 if ( !isset($collate) ) 550 $collate = $this->collate; 551 if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) { 552 if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) { 553 mysql_set_charset( $charset, $dbh ); 554 $this->real_escape = true; 555 } else { 556 $query = $this->prepare( 'SET NAMES %s', $charset ); 557 if ( ! empty( $collate ) ) 558 $query .= $this->prepare( ' COLLATE %s', $collate ); 559 mysql_query( $query, $dbh ); 560 } 561 } 562 } 563 564 /** 565 * Sets the table prefix for the WordPress tables. 566 * 567 * @since 2.5.0 568 * 569 * @param string $prefix Alphanumeric name for the new prefix. 570 * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not. 571 * @return string|WP_Error Old prefix or WP_Error on error 572 */ 573 function set_prefix( $prefix, $set_table_names = true ) { 574 575 if ( preg_match( '|[^a-z0-9_]|i', $prefix ) ) 576 return new WP_Error('invalid_db_prefix', 'Invalid database prefix' ); 577 578 $old_prefix = is_multisite() ? '' : $prefix; 579 580 if ( isset( $this->base_prefix ) ) 581 $old_prefix = $this->base_prefix; 582 583 $this->base_prefix = $prefix; 584 585 if ( $set_table_names ) { 586 foreach ( $this->tables( 'global' ) as $table => $prefixed_table ) 587 $this->$table = $prefixed_table; 588 589 if ( is_multisite() && empty( $this->blogid ) ) 590 return $old_prefix; 591 592 $this->prefix = $this->get_blog_prefix(); 593 594 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) 595 $this->$table = $prefixed_table; 596 597 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) 598 $this->$table = $prefixed_table; 599 } 600 return $old_prefix; 601 } 602 603 /** 604 * Sets blog id. 605 * 606 * @since 3.0.0 607 * @access public 608 * @param int $blog_id 609 * @param int $site_id Optional. 610 * @return string previous blog id 611 */ 612 function set_blog_id( $blog_id, $site_id = 0 ) { 613 if ( ! empty( $site_id ) ) 614 $this->siteid = $site_id; 615 616 $old_blog_id = $this->blogid; 617 $this->blogid = $blog_id; 618 619 $this->prefix = $this->get_blog_prefix(); 620 621 foreach ( $this->tables( 'blog' ) as $table => $prefixed_table ) 622 $this->$table = $prefixed_table; 623 624 foreach ( $this->tables( 'old' ) as $table => $prefixed_table ) 625 $this->$table = $prefixed_table; 626 627 return $old_blog_id; 628 } 629 630 /** 631 * Gets blog prefix. 632 * 633 * @uses is_multisite() 634 * @since 3.0.0 635 * @param int $blog_id Optional. 636 * @return string Blog prefix. 637 */ 638 function get_blog_prefix( $blog_id = null ) { 639 if ( is_multisite() ) { 640 if ( null === $blog_id ) 641 $blog_id = $this->blogid; 642 $blog_id = (int) $blog_id; 643 if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) ) 644 return $this->base_prefix; 645 else 646 return $this->base_prefix . $blog_id . '_'; 647 } else { 648 return $this->base_prefix; 649 } 650 } 651 652 /** 653 * Returns an array of WordPress tables. 654 * 655 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to 656 * override the WordPress users and usermeta tables that would otherwise 657 * be determined by the prefix. 658 * 659 * The scope argument can take one of the following: 660 * 661 * 'all' - returns 'all' and 'global' tables. No old tables are returned. 662 * 'blog' - returns the blog-level tables for the queried blog. 663 * 'global' - returns the global tables for the installation, returning multisite tables only if running multisite. 664 * 'ms_global' - returns the multisite global tables, regardless if current installation is multisite. 665 * 'old' - returns tables which are deprecated. 666 * 667 * @since 3.0.0 668 * @uses wpdb::$tables 669 * @uses wpdb::$old_tables 670 * @uses wpdb::$global_tables 671 * @uses wpdb::$ms_global_tables 672 * @uses is_multisite() 673 * 674 * @param string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all. 675 * @param bool $prefix Optional. Whether to include table prefixes. Default true. If blog 676 * prefix is requested, then the custom users and usermeta tables will be mapped. 677 * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested. 678 * @return array Table names. When a prefix is requested, the key is the unprefixed table name. 679 */ 680 function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) { 681 switch ( $scope ) { 682 case 'all' : 683 $tables = array_merge( $this->global_tables, $this->tables ); 684 if ( is_multisite() ) 685 $tables = array_merge( $tables, $this->ms_global_tables ); 686 break; 687 case 'blog' : 688 $tables = $this->tables; 689 break; 690 case 'global' : 691 $tables = $this->global_tables; 692 if ( is_multisite() ) 693 $tables = array_merge( $tables, $this->ms_global_tables ); 694 break; 695 case 'ms_global' : 696 $tables = $this->ms_global_tables; 697 break; 698 case 'old' : 699 $tables = $this->old_tables; 700 break; 701 default : 702 return array(); 703 break; 704 } 705 706 if ( $prefix ) { 707 if ( ! $blog_id ) 708 $blog_id = $this->blogid; 709 $blog_prefix = $this->get_blog_prefix( $blog_id ); 710 $base_prefix = $this->base_prefix; 711 $global_tables = array_merge( $this->global_tables, $this->ms_global_tables ); 712 foreach ( $tables as $k => $table ) { 713 if ( in_array( $table, $global_tables ) ) 714 $tables[ $table ] = $base_prefix . $table; 715 else 716 $tables[ $table ] = $blog_prefix . $table; 717 unset( $tables[ $k ] ); 718 } 719 720 if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) ) 721 $tables['users'] = CUSTOM_USER_TABLE; 722 723 if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) ) 724 $tables['usermeta'] = CUSTOM_USER_META_TABLE; 725 } 726 727 return $tables; 728 } 729 730 /** 731 * Selects a database using the current database connection. 732 * 733 * The database name will be changed based on the current database 734 * connection. On failure, the execution will bail and display an DB error. 735 * 736 * @since 0.71 737 * 738 * @param string $db MySQL database name 739 * @param resource $dbh Optional link identifier. 740 * @return null Always null. 741 */ 742 function select( $db, $dbh = null ) { 743 if ( is_null($dbh) ) 744 $dbh = $this->dbh; 745 746 if ( !@mysql_select_db( $db, $dbh ) ) { 747 $this->ready = false; 748 wp_load_translations_early(); 749 $this->bail( sprintf( __( '<h1>Can’t select database</h1> 750 <p>We were able to connect to the database server (which means your username and password is okay) but not able to select the <code>%1$s</code> database.</p> 751 <ul> 752 <li>Are you sure it exists?</li> 753 <li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li> 754 <li>On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?</li> 755 </ul> 756 <p>If you don\'t know how to set up a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="http://wordpress.org/support/">WordPress Support Forums</a>.</p>' ), $db, $this->dbuser ), 'db_select_fail' ); 757 return; 758 } 759 } 760 761 /** 762 * Weak escape, using addslashes() 763 * 764 * @see addslashes() 765 * @since 2.8.0 766 * @access private 767 * 768 * @param string $string 769 * @return string 770 */ 771 function _weak_escape( $string ) { 772 return addslashes( $string ); 773 } 774 775 /** 776 * Real escape, using mysql_real_escape_string() or addslashes() 777 * 778 * @see mysql_real_escape_string() 779 * @see addslashes() 780 * @since 2.8.0 781 * @access private 782 * 783 * @param string $string to escape 784 * @return string escaped 785 */ 786 function _real_escape( $string ) { 787 if ( $this->dbh && $this->real_escape ) 788 return mysql_real_escape_string( $string, $this->dbh ); 789 else 790 return addslashes( $string ); 791 } 792 793 /** 794 * Escape data. Works on arrays. 795 * 796 * @uses wpdb::_escape() 797 * @uses wpdb::_real_escape() 798 * @since 2.8.0 799 * @access private 800 * 801 * @param string|array $data 802 * @return string|array escaped 803 */ 804 function _escape( $data ) { 805 if ( is_array( $data ) ) { 806 foreach ( (array) $data as $k => $v ) { 807 if ( is_array($v) ) 808 $data[$k] = $this->_escape( $v ); 809 else 810 $data[$k] = $this->_real_escape( $v ); 811 } 812 } else { 813 $data = $this->_real_escape( $data ); 814 } 815 816 return $data; 817 } 818 819 /** 820 * Escapes content for insertion into the database using addslashes(), for security. 821 * 822 * Works on arrays. 823 * 824 * @since 0.71 825 * @param string|array $data to escape 826 * @return string|array escaped as query safe string 827 */ 828 function escape( $data ) { 829 if ( is_array( $data ) ) { 830 foreach ( (array) $data as $k => $v ) { 831 if ( is_array( $v ) ) 832 $data[$k] = $this->escape( $v ); 833 else 834 $data[$k] = $this->_weak_escape( $v ); 835 } 836 } else { 837 $data = $this->_weak_escape( $data ); 838 } 839 840 return $data; 841 } 842 843 /** 844 * Escapes content by reference for insertion into the database, for security 845 * 846 * @uses wpdb::_real_escape() 847 * @since 2.3.0 848 * @param string $string to escape 849 * @return void 850 */ 851 function escape_by_ref( &$string ) { 852 $string = $this->_real_escape( $string ); 853 } 854 855 /** 856 * Prepares a SQL query for safe execution. Uses sprintf()-like syntax. 857 * 858 * The following directives can be used in the query format string: 859 * %d (integer) 860 * %f (float) 861 * %s (string) 862 * %% (literal percentage sign - no argument needed) 863 * 864 * All of %d, %f, and %s are to be left unquoted in the query string and they need an argument passed for them. 865 * Literals (%) as parts of the query must be properly written as %%. 866 * 867 * This function only supports a small subset of the sprintf syntax; it only supports %d (integer), %f (float), and %s (string). 868 * Does not support sign, padding, alignment, width or precision specifiers. 869 * Does not support argument numbering/swapping. 870 * 871 * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}. 872 * 873 * Both %d and %s should be left unquoted in the query string. 874 * 875 * <code> 876 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 ) 877 * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' ); 878 * </code> 879 * 880 * @link http://php.net/sprintf Description of syntax. 881 * @since 2.3.0 882 * 883 * @param string $query Query statement with sprintf()-like placeholders 884 * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like 885 * {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if 886 * being called like {@link http://php.net/sprintf sprintf()}. 887 * @param mixed $args,... further variables to substitute into the query's placeholders if being called like 888 * {@link http://php.net/sprintf sprintf()}. 889 * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string 890 * if there was something to prepare 891 */ 892 function prepare( $query = null ) { // ( $query, *$args ) 893 if ( is_null( $query ) ) 894 return; 895 896 $args = func_get_args(); 897 array_shift( $args ); 898 // If args were passed as an array (as in vsprintf), move them up 899 if ( isset( $args[0] ) && is_array($args[0]) ) 900 $args = $args[0]; 901 $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it 902 $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting 903 $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s 904 array_walk( $args, array( &$this, 'escape_by_ref' ) ); 905 return @vsprintf( $query, $args ); 906 } 907 908 /** 909 * Print SQL/DB error. 910 * 911 * @since 0.71 912 * @global array $EZSQL_ERROR Stores error information of query and error string 913 * 914 * @param string $str The error to display 915 * @return bool False if the showing of errors is disabled. 916 */ 917 function print_error( $str = '' ) { 918 global $EZSQL_ERROR; 919 920 if ( !$str ) 921 $str = mysql_error( $this->dbh ); 922 $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str ); 923 924 if ( $this->suppress_errors ) 925 return false; 926 927 wp_load_translations_early(); 928 929 if ( $caller = $this->get_caller() ) 930 $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller ); 931 else 932 $error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query ); 933 934 if ( function_exists( 'error_log' ) 935 && ( $log_file = @ini_get( 'error_log' ) ) 936 && ( 'syslog' == $log_file || @is_writable( $log_file ) ) 937 ) 938 @error_log( $error_str ); 939 940 // Are we showing errors? 941 if ( ! $this->show_errors ) 942 return false; 943 944 // If there is an error then take note of it 945 if ( is_multisite() ) { 946 $msg = "WordPress database error: [$str]\n{$this->last_query}\n"; 947 if ( defined( 'ERRORLOGFILE' ) ) 948 error_log( $msg, 3, ERRORLOGFILE ); 949 if ( defined( 'DIEONDBERROR' ) ) 950 wp_die( $msg ); 951 } else { 952 $str = htmlspecialchars( $str, ENT_QUOTES ); 953 $query = htmlspecialchars( $this->last_query, ENT_QUOTES ); 954 955 print "<div id='error'> 956 <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br /> 957 <code>$query</code></p> 958 </div>"; 959 } 960 } 961 962 /** 963 * Enables showing of database errors. 964 * 965 * This function should be used only to enable showing of errors. 966 * wpdb::hide_errors() should be used instead for hiding of errors. However, 967 * this function can be used to enable and disable showing of database 968 * errors. 969 * 970 * @since 0.71 971 * @see wpdb::hide_errors() 972 * 973 * @param bool $show Whether to show or hide errors 974 * @return bool Old value for showing errors. 975 */ 976 function show_errors( $show = true ) { 977 $errors = $this->show_errors; 978 $this->show_errors = $show; 979 return $errors; 980 } 981 982 /** 983 * Disables showing of database errors. 984 * 985 * By default database errors are not shown. 986 * 987 * @since 0.71 988 * @see wpdb::show_errors() 989 * 990 * @return bool Whether showing of errors was active 991 */ 992 function hide_errors() { 993 $show = $this->show_errors; 994 $this->show_errors = false; 995 return $show; 996 } 997 998 /** 999 * Whether to suppress database errors. 1000 * 1001 * By default database errors are suppressed, with a simple 1002 * call to this function they can be enabled. 1003 * 1004 * @since 2.5.0 1005 * @see wpdb::hide_errors() 1006 * @param bool $suppress Optional. New value. Defaults to true. 1007 * @return bool Old value 1008 */ 1009 function suppress_errors( $suppress = true ) { 1010 $errors = $this->suppress_errors; 1011 $this->suppress_errors = (bool) $suppress; 1012 return $errors; 1013 } 1014 1015 /** 1016 * Kill cached query results. 1017 * 1018 * @since 0.71 1019 * @return void 1020 */ 1021 function flush() { 1022 $this->last_result = array(); 1023 $this->col_info = null; 1024 $this->last_query = null; 1025 } 1026 1027 /** 1028 * Connect to and select database 1029 * 1030 * @since 3.0.0 1031 */ 1032 function db_connect() { 1033 1034 $this->is_mysql = true; 1035 1036 if ( WP_DEBUG ) { 1037 $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 1038 } else { 1039 $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); 1040 } 1041 1042 if ( !$this->dbh ) { 1043 wp_load_translations_early(); 1044 $this->bail( sprintf( __( " 1045 <h1>Error establishing a database connection</h1> 1046 <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p> 1047 <ul> 1048 <li>Are you sure you have the correct username and password?</li> 1049 <li>Are you sure that you have typed the correct hostname?</li> 1050 <li>Are you sure that the database server is running?</li> 1051 </ul> 1052 <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p> 1053 " ), $this->dbhost ), 'db_connect_fail' ); 1054 1055 return; 1056 } 1057 1058 $this->set_charset( $this->dbh ); 1059 1060 $this->ready = true; 1061 1062 $this->select( $this->dbname, $this->dbh ); 1063 } 1064 1065 /** 1066 * Perform a MySQL database query, using current database connection. 1067 * 1068 * More information can be found on the codex page. 1069 * 1070 * @since 0.71 1071 * 1072 * @param string $query Database query 1073 * @return int|false Number of rows affected/selected or false on error 1074 */ 1075 function query( $query ) { 1076 if ( ! $this->ready ) 1077 return false; 1078 1079 // some queries are made before the plugins have been loaded, and thus cannot be filtered with this method 1080 $query = apply_filters( 'query', $query ); 1081 1082 $return_val = 0; 1083 $this->flush(); 1084 1085 // Log how the function was called 1086 $this->func_call = "\$db->query(\"$query\")"; 1087 1088 // Keep track of the last query for debug.. 1089 $this->last_query = $query; 1090 1091 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1092 $this->timer_start(); 1093 1094 $this->result = @mysql_query( $query, $this->dbh ); 1095 $this->num_queries++; 1096 1097 if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES ) 1098 $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() ); 1099 1100 // If there is an error then take note of it.. 1101 if ( $this->last_error = mysql_error( $this->dbh ) ) { 1102 $this->print_error(); 1103 return false; 1104 } 1105 1106 if ( preg_match( '/^\s*(create|alter|truncate|drop) /i', $query ) ) { 1107 $return_val = $this->result; 1108 } elseif ( preg_match( '/^\s*(insert|delete|update|replace) /i', $query ) ) { 1109 $this->rows_affected = mysql_affected_rows( $this->dbh ); 1110 // Take note of the insert_id 1111 if ( preg_match( '/^\s*(insert|replace) /i', $query ) ) { 1112 $this->insert_id = mysql_insert_id($this->dbh); 1113 } 1114 // Return number of rows affected 1115 $return_val = $this->rows_affected; 1116 } else { 1117 $i = 0; 1118 while ( $i < @mysql_num_fields( $this->result ) ) { 1119 $this->col_info[$i] = @mysql_fetch_field( $this->result ); 1120 $i++; 1121 } 1122 $num_rows = 0; 1123 while ( $row = @mysql_fetch_object( $this->result ) ) { 1124 $this->last_result[$num_rows] = $row; 1125 $num_rows++; 1126 } 1127 1128 @mysql_free_result( $this->result ); 1129 1130 // Log number of rows the query returned 1131 // and return number of rows selected 1132 $this->num_rows = $num_rows; 1133 $return_val = $num_rows; 1134 } 1135 1136 return $return_val; 1137 } 1138 1139 /** 1140 * Insert a row into a table. 1141 * 1142 * <code> 1143 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) 1144 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 1145 * </code> 1146 * 1147 * @since 2.5.0 1148 * @see wpdb::prepare() 1149 * @see wpdb::$field_types 1150 * @see wp_set_wpdb_vars() 1151 * 1152 * @param string $table table name 1153 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1154 * @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. 1155 * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1156 * @return int|false The number of rows inserted, or false on error. 1157 */ 1158 function insert( $table, $data, $format = null ) { 1159 return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); 1160 } 1161 1162 /** 1163 * Replace a row into a table. 1164 * 1165 * <code> 1166 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) 1167 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 1168 * </code> 1169 * 1170 * @since 3.0.0 1171 * @see wpdb::prepare() 1172 * @see wpdb::$field_types 1173 * @see wp_set_wpdb_vars() 1174 * 1175 * @param string $table table name 1176 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1177 * @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. 1178 * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1179 * @return int|false The number of rows affected, or false on error. 1180 */ 1181 function replace( $table, $data, $format = null ) { 1182 return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); 1183 } 1184 1185 /** 1186 * Helper function for insert and replace. 1187 * 1188 * Runs an insert or replace query based on $type argument. 1189 * 1190 * @access private 1191 * @since 3.0.0 1192 * @see wpdb::prepare() 1193 * @see wpdb::$field_types 1194 * @see wp_set_wpdb_vars() 1195 * 1196 * @param string $table table name 1197 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1198 * @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. 1199 * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1200 * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT. 1201 * @return int|false The number of rows affected, or false on error. 1202 */ 1203 function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { 1204 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) 1205 return false; 1206 $formats = $format = (array) $format; 1207 $fields = array_keys( $data ); 1208 $formatted_fields = array(); 1209 foreach ( $fields as $field ) { 1210 if ( !empty( $format ) ) 1211 $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 1212 elseif ( isset( $this->field_types[$field] ) ) 1213 $form = $this->field_types[$field]; 1214 else 1215 $form = '%s'; 1216 $formatted_fields[] = $form; 1217 } 1218 $sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")"; 1219 return $this->query( $this->prepare( $sql, $data ) ); 1220 } 1221 1222 /** 1223 * Update a row in the table 1224 * 1225 * <code> 1226 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) ) 1227 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 1228 * </code> 1229 * 1230 * @since 2.5.0 1231 * @see wpdb::prepare() 1232 * @see wpdb::$field_types 1233 * @see wp_set_wpdb_vars() 1234 * 1235 * @param string $table table name 1236 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1237 * @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". 1238 * @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. 1239 * A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1240 * @param array|string $where_format 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', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings. 1241 * @return int|false The number of rows updated, or false on error. 1242 */ 1243 function update( $table, $data, $where, $format = null, $where_format = null ) { 1244 if ( ! is_array( $data ) || ! is_array( $where ) ) 1245 return false; 1246 1247 $formats = $format = (array) $format; 1248 $bits = $wheres = array(); 1249 foreach ( (array) array_keys( $data ) as $field ) { 1250 if ( !empty( $format ) ) 1251 $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; 1252 elseif ( isset($this->field_types[$field]) ) 1253 $form = $this->field_types[$field]; 1254 else 1255 $form = '%s'; 1256 $bits[] = "`$field` = {$form}"; 1257 } 1258 1259 $where_formats = $where_format = (array) $where_format; 1260 foreach ( (array) array_keys( $where ) as $field ) { 1261 if ( !empty( $where_format ) ) 1262 $form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0]; 1263 elseif ( isset( $this->field_types[$field] ) ) 1264 $form = $this->field_types[$field]; 1265 else 1266 $form = '%s'; 1267 $wheres[] = "`$field` = {$form}"; 1268 } 1269 1270 $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ); 1271 return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); 1272 } 1273 1274 /** 1275 * Retrieve one variable from the database. 1276 * 1277 * Executes a SQL query and returns the value from the SQL result. 1278 * If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified. 1279 * If $query is null, this function returns the value in the specified column and row from the previous SQL result. 1280 * 1281 * @since 0.71 1282 * 1283 * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query. 1284 * @param int $x Optional. Column of value to return. Indexed from 0. 1285 * @param int $y Optional. Row of value to return. Indexed from 0. 1286 * @return string|null Database query result (as string), or null on failure 1287 */ 1288 function get_var( $query = null, $x = 0, $y = 0 ) { 1289 $this->func_call = "\$db->get_var(\"$query\", $x, $y)"; 1290 if ( $query ) 1291 $this->query( $query ); 1292 1293 // Extract var out of cached results based x,y vals 1294 if ( !empty( $this->last_result[$y] ) ) { 1295 $values = array_values( get_object_vars( $this->last_result[$y] ) ); 1296 } 1297 1298 // If there is a value return it else return null 1299 return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null; 1300 } 1301 1302 /** 1303 * Retrieve one row from the database. 1304 * 1305 * Executes a SQL query and returns the row from the SQL result. 1306 * 1307 * @since 0.71 1308 * 1309 * @param string|null $query SQL query. 1310 * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), 1311 * a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 1312 * @param int $y Optional. Row to return. Indexed from 0. 1313 * @return mixed Database query result in format specified by $output or null on failure 1314 */ 1315 function get_row( $query = null, $output = OBJECT, $y = 0 ) { 1316 $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 1317 if ( $query ) 1318 $this->query( $query ); 1319 else 1320 return null; 1321 1322 if ( !isset( $this->last_result[$y] ) ) 1323 return null; 1324 1325 if ( $output == OBJECT ) { 1326 return $this->last_result[$y] ? $this->last_result[$y] : null; 1327 } elseif ( $output == ARRAY_A ) { 1328 return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null; 1329 } elseif ( $output == ARRAY_N ) { 1330 return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null; 1331 } else { 1332 $this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" ); 1333 } 1334 } 1335 1336 /** 1337 * Retrieve one column from the database. 1338 * 1339 * Executes a SQL query and returns the column from the SQL result. 1340 * If the SQL result contains more than one column, this function returns the column specified. 1341 * If $query is null, this function returns the specified column from the previous SQL result. 1342 * 1343 * @since 0.71 1344 * 1345 * @param string|null $query Optional. SQL query. Defaults to previous query. 1346 * @param int $x Optional. Column to return. Indexed from 0. 1347 * @return array Database query result. Array indexed from 0 by SQL result row number. 1348 */ 1349 function get_col( $query = null , $x = 0 ) { 1350 if ( $query ) 1351 $this->query( $query ); 1352 1353 $new_array = array(); 1354 // Extract the column values 1355 for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) { 1356 $new_array[$i] = $this->get_var( null, $x, $i ); 1357 } 1358 return $new_array; 1359 } 1360 1361 /** 1362 * Retrieve an entire SQL result set from the database (i.e., many rows) 1363 * 1364 * Executes a SQL query and returns the entire SQL result. 1365 * 1366 * @since 0.71 1367 * 1368 * @param string $query SQL query. 1369 * @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. 1370 * Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively. 1371 * 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. 1372 * @return mixed Database query results 1373 */ 1374 function get_results( $query = null, $output = OBJECT ) { 1375 $this->func_call = "\$db->get_results(\"$query\", $output)"; 1376 1377 if ( $query ) 1378 $this->query( $query ); 1379 else 1380 return null; 1381 1382 $new_array = array(); 1383 if ( $output == OBJECT ) { 1384 // Return an integer-keyed array of row objects 1385 return $this->last_result; 1386 } elseif ( $output == OBJECT_K ) { 1387 // Return an array of row objects with keys from column 1 1388 // (Duplicates are discarded) 1389 foreach ( $this->last_result as $row ) { 1390 $var_by_ref = get_object_vars( $row ); 1391 $key = array_shift( $var_by_ref ); 1392 if ( ! isset( $new_array[ $key ] ) ) 1393 $new_array[ $key ] = $row; 1394 } 1395 return $new_array; 1396 } elseif ( $output == ARRAY_A || $output == ARRAY_N ) { 1397 // Return an integer-keyed array of... 1398 if ( $this->last_result ) { 1399 foreach( (array) $this->last_result as $row ) { 1400 if ( $output == ARRAY_N ) { 1401 // ...integer-keyed row arrays 1402 $new_array[] = array_values( get_object_vars( $row ) ); 1403 } else { 1404 // ...column name-keyed row arrays 1405 $new_array[] = get_object_vars( $row ); 1406 } 1407 } 1408 } 1409 return $new_array; 1410 } 1411 return null; 1412 } 1413 1414 /** 1415 * Retrieve column metadata from the last query. 1416 * 1417 * @since 0.71 1418 * 1419 * @param string $info_type Optional. Type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill 1420 * @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 * @return mixed Column Results 1422 */ 1423 function get_col_info( $info_type = 'name', $col_offset = -1 ) { 1424 if ( $this->col_info ) { 1425 if ( $col_offset == -1 ) { 1426 $i = 0; 1427 $new_array = array(); 1428 foreach( (array) $this->col_info as $col ) { 1429 $new_array[$i] = $col->{$info_type}; 1430 $i++; 1431 } 1432 return $new_array; 1433 } else { 1434 return $this->col_info[$col_offset]->{$info_type}; 1435 } 1436 } 1437 } 1438 1439 /** 1440 * Starts the timer, for debugging purposes. 1441 * 1442 * @since 1.5.0 1443 * 1444 * @return true 1445 */ 1446 function timer_start() { 1447 $this->time_start = microtime( true ); 1448 return true; 1449 } 1450 1451 /** 1452 * Stops the debugging timer. 1453 * 1454 * @since 1.5.0 1455 * 1456 * @return float Total time spent on the query, in seconds 1457 */ 1458 function timer_stop() { 1459 return ( microtime( true ) - $this->time_start ); 1460 } 1461 1462 /** 1463 * Wraps errors in a nice header and footer and dies. 1464 * 1465 * Will not die if wpdb::$show_errors is true 1466 * 1467 * @since 1.5.0 1468 * 1469 * @param string $message The Error message 1470 * @param string $error_code Optional. A Computer readable string to identify the error. 1471 * @return false|void 1472 */ 1473 function bail( $message, $error_code = '500' ) { 1474 if ( !$this->show_errors ) { 1475 if ( class_exists( 'WP_Error' ) ) 1476 $this->error = new WP_Error($error_code, $message); 1477 else 1478 $this->error = $message; 1479 return false; 1480 } 1481 wp_die($message); 1482 } 1483 1484 /** 1485 * Whether MySQL database is at least the required minimum version. 1486 * 1487 * @since 2.5.0 1488 * @uses $wp_version 1489 * @uses $required_mysql_version 1490 * 1491 * @return WP_Error 1492 */ 1493 function check_database_version() { 1494 global $wp_version, $required_mysql_version; 1495 // Make sure the server has the required MySQL version 1496 if ( version_compare($this->db_version(), $required_mysql_version, '<') ) 1497 return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version )); 1498 } 1499 1500 /** 1501 * Whether the database supports collation. 1502 * 1503 * Called when WordPress is generating the table scheme. 1504 * 1505 * @since 2.5.0 1506 * 1507 * @return bool True if collation is supported, false if version does not 1508 */ 1509 function supports_collation() { 1510 return $this->has_cap( 'collation' ); 1511 } 1512 1513 /** 1514 * Determine if a database supports a particular feature 1515 * 1516 * @since 2.7.0 1517 * @see wpdb::db_version() 1518 * 1519 * @param string $db_cap the feature 1520 * @return bool 1521 */ 1522 function has_cap( $db_cap ) { 1523 $version = $this->db_version(); 1524 1525 switch ( strtolower( $db_cap ) ) { 1526 case 'collation' : // @since 2.5.0 1527 case 'group_concat' : // @since 2.7 1528 case 'subqueries' : // @since 2.7 1529 return version_compare( $version, '4.1', '>=' ); 1530 case 'set_charset' : 1531 return version_compare($version, '5.0.7', '>='); 1532 }; 1533 1534 return false; 1535 } 1536 1537 /** 1538 * Retrieve the name of the function that called wpdb. 1539 * 1540 * Searches up the list of functions until it reaches 1541 * the one that would most logically had called this method. 1542 * 1543 * @since 2.5.0 1544 * 1545 * @return string The name of the calling function 1546 */ 1547 function get_caller() { 1548 return wp_debug_backtrace_summary( __CLASS__ ); 1549 } 1550 1551 /** 1552 * The database version number. 1553 * 1554 * @since 2.7.0 1555 * 1556 * @return false|string false on failure, version number on success 1557 */ 1558 function db_version() { 1559 return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) ); 1560 } 1561 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Feb 7 03:55:55 2012 | Hosted by follow the white rabbit. |