Ticket #9506: 9506.diff
| File 9506.diff, 12.0 KB (added by , 17 years ago) |
|---|
-
wp-includes/wp-db.php
373 373 * Sets the table prefix for the WordPress tables. 374 374 * 375 375 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to 376 * override the WordPress users and usersmeta tables .376 * override the WordPress users and usersmeta tables that would otherwise be determined by the $prefix. 377 377 * 378 378 * @since 2.5.0 379 379 * 380 380 * @param string $prefix Alphanumeric name for the new prefix. 381 * @return string Old prefix381 * @return string|WP_Error Old prefix or WP_Error on error 382 382 */ 383 383 function set_prefix($prefix) { 384 384 … … 488 488 } 489 489 490 490 /** 491 * Prepares a SQL query for safe use, using sprintf()syntax.491 * Prepares a SQL query for safe execution. Uses sprintf()-like syntax. 492 492 * 493 * @link http://php.net/sprintf See for syntax to use for query string. 493 * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string). 494 * Does not support sign, padding, alignment, width or precision specifiers. 495 * Does not support argument numbering/swapping. 496 * 497 * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}. 498 * 499 * Both %d and %s should be left unquoted in the query string. 500 * 501 * <code> 502 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 503 * </code> 504 * 505 * @link http://php.net/sprintf Description of syntax. 494 506 * @since 2.3.0 495 507 * 496 * @param null|string $args If string, first parameter must be query statement 497 * @param mixed $args,... If additional parameters, they will be set inserted into the query. 508 * @param string $query Query statement with sprintf()-like placeholders 509 * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 510 * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 498 511 * @return null|string Sanitized query string 499 512 */ 500 function prepare($ args=null) {501 if ( is_null( $ args) )513 function prepare($query = null) { // ( $query, *$args ) 514 if ( is_null( $query ) ) 502 515 return; 503 516 $args = func_get_args(); 504 $query =array_shift($args);505 // If args were passed as an array , move them up517 array_shift($args); 518 // If args were passed as an array (as in vsprintf), move them up 506 519 if ( isset($args[0]) && is_array($args[0]) ) 507 520 $args = $args[0]; 508 521 $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it … … 623 636 * @since 0.71 624 637 * 625 638 * @param string $query 626 * @return unknown639 * @return int|false Number of rows affected/selected or false on error 627 640 */ 628 641 function query($query) { 629 642 if ( ! $this->ready ) … … 693 706 } 694 707 695 708 /** 696 * Insert a n array of datainto a table.709 * Insert a row into a table. 697 710 * 711 * <code> 712 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 713 * </code> 714 * 698 715 * @since 2.5.0 716 * @see wpdb::prepare() 699 717 * 700 718 * @param string $table table name 701 * @param array $data Should not already be SQL-escaped702 * @param array|string $format The format of the field values.703 * @return mixed Results of $this->query()719 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 720 * @param array|string $format (optional) An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings. 721 * @return int|false The number of rows inserted, or false on error. 704 722 */ 705 723 function insert($table, $data, $format = null) { 706 724 global $db_field_types; … … 721 739 return $this->query( $this->prepare( $sql, $data) ); 722 740 } 723 741 742 724 743 /** 725 * Update a row in the table with an array of data.744 * Update a row in the table 726 745 * 746 * <code> 747 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 748 * </code> 749 * 727 750 * @since 2.5.0 751 * @see wpdb::prepare() 728 752 * 729 753 * @param string $table table name 730 * @param array $data Should not already be SQL-escaped731 * @param array $where A named array of WHERE c olumn => value relationships. Multiple member pairs will be joined with ANDs.732 * @param array|string $format The format of the field values.733 * @param array|string $ where_format The format of the where field values.734 * @return mixed Results of $this->query()754 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 755 * @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". 756 * @param array|string $format (optional) An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data. A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings. 757 * @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. 758 * @return int|false The number of rows updated, or false on error. 735 759 */ 736 760 function update($table, $data, $where, $format = null, $where_format = null) { 737 761 global $db_field_types; … … 769 793 /** 770 794 * Retrieve one variable from the database. 771 795 * 772 * This combines the functionality of wpdb::get_row() and wpdb::get_col(), 773 * so both the column and row can be picked. 796 * Executes a SQL query and returns the value from the SQL result. 797 * 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. 798 * If $query is null, this function returns the value in the specified column and row from the previous SQL result. 774 799 * 775 * It is possible to use this function without executing more queries. If776 * you already made a query, you can set the $query to 'null' value and just777 * retrieve either the column and row of the last query result.778 *779 800 * @since 0.71 780 801 * 781 * @param string $query Can be null as well, for caching782 * @param int $x Column num to return783 * @param int $y Row num to return784 * @return mixed Database query results802 * @param string|null $query SQL query. If null, use the result from the previous query. 803 * @param int $x (optional) Column of value to return. Indexed from 0. 804 * @param int $y (optional) Row of value to return. Indexed from 0. 805 * @return string Database query result 785 806 */ 786 807 function get_var($query=null, $x = 0, $y = 0) { 787 808 $this->func_call = "\$db->get_var(\"$query\",$x,$y)"; … … 800 821 /** 801 822 * Retrieve one row from the database. 802 823 * 824 * Executes a SQL query and returns the row from the SQL result. 825 * 803 826 * @since 0.71 804 827 * 805 * @param string $query SQL query806 * @param string $output ARRAY_A | ARRAY_N | OBJECT807 * @param int $y Row num to return808 * @return mixed Database query result s828 * @param string|null $query SQL query. 829 * @param string $output (optional) one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively. 830 * @param int $y (optional) Row to return. Indexed from 0. 831 * @return mixed Database query result in format specifed by $output 809 832 */ 810 833 function get_row($query = null, $output = OBJECT, $y = 0) { 811 834 $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; … … 831 854 /** 832 855 * Retrieve one column from the database. 833 856 * 857 * Executes a SQL query and returns the column from the SQL result. 858 * If the SQL result contains more than one column, this function returns the column specified. 859 * If $query is null, this function returns the specified column from the previous SQL result. 860 * 834 861 * @since 0.71 835 862 * 836 * @param string $query Can be null as well, for caching837 * @param int $x Col num to return. Startsfrom 0.838 * @return array Column results863 * @param string|null $query SQL query. If null, use the result from the previous query. 864 * @param int $x Column to return. Indexed from 0. 865 * @return array Database query result. Array indexed from 0 by SQL result row number. 839 866 */ 840 867 function get_col($query = null , $x = 0) { 841 868 if ( $query ) … … 850 877 } 851 878 852 879 /** 853 * Retrieve an entire result set from the database.880 * Retrieve an entire SQL result set from the database (i.e., many rows) 854 881 * 882 * Executes a SQL query and returns the entire SQL result. 883 * 855 884 * @since 0.71 856 885 * 857 * @param string |null $query Can also be null to pull from the cache858 * @param string $output ARRAY_A | ARRAY_N | OBJECT_K | OBJECT886 * @param string $query SQL query. 887 * @param string $output (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. With one of the first three, return an array of rows indexed from 0 by SQL result row number. Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively. With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded. 859 888 * @return mixed Database query results 860 889 */ 861 890 function get_results($query = null, $output = OBJECT) { … … 926 955 * 927 956 * @since 1.5.0 928 957 * 929 * @return bool Always returnstrue958 * @return true 930 959 */ 931 960 function timer_start() { 932 961 $mtime = microtime(); … … 951 980 } 952 981 953 982 /** 954 * Wraps fatalerrors in a nice header and footer and dies.983 * Wraps errors in a nice header and footer and dies. 955 984 * 985 * Will not die if wpdb::$show_errors is true 986 * 956 987 * @since 1.5.0 957 988 * 958 989 * @param string $message 959 * @return unknown990 * @return false|void 960 991 */ 961 992 function bail($message) { 962 993 if ( !$this->show_errors ) { … … 970 1001 } 971 1002 972 1003 /** 973 * Whether or not MySQL database is minimal requiredversion.1004 * Whether or not MySQL database is at least the required minimum version. 974 1005 * 975 1006 * @since 2.5.0 976 1007 * @uses $wp_version … … 986 1017 } 987 1018 988 1019 /** 989 * Whether of not the database versionsupports collation.1020 * Whether of not the database supports collation. 990 1021 * 991 1022 * Called when WordPress is generating the table scheme. 992 1023 * … … 1002 1033 /** 1003 1034 * Generic function to determine if a database supports a particular feature 1004 1035 * @param string $db_cap the feature 1005 * @param false|string|resource $dbh_or_table the databaese (the current database, the database housing the specified table, or the database of the mysql resource)1036 * @param false|string|resource $dbh_or_table (not implemented) Which database to test. False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource. 1006 1037 * @return bool 1007 1038 */ 1008 1039 function has_cap( $db_cap ) { … … 1053 1084 1054 1085 /** 1055 1086 * The database version number 1087 * @param false|string|resource $dbh_or_table (not implemented) Which database to test. False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource. 1056 1088 * @return false|string false on failure, version number on success 1057 1089 */ 1058 1090 function db_version() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)