Changeset 10911
- Timestamp:
- 04/10/2009 09:57:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-db.php
r10910 r10911 388 388 * 389 389 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to 390 * override the WordPress users and usersmeta tables .390 * override the WordPress users and usersmeta tables that would otherwise be determined by the $prefix. 391 391 * 392 392 * @since 2.5.0 393 393 * 394 394 * @param string $prefix Alphanumeric name for the new prefix. 395 * @return string Old prefix395 * @return string|WP_Error Old prefix or WP_Error on error 396 396 */ 397 397 function set_prefix($prefix) { … … 503 503 504 504 /** 505 * Prepares a SQL query for safe use, using sprintf() syntax. 506 * 507 * @link http://php.net/sprintf See for syntax to use for query string. 505 * Prepares a SQL query for safe execution. Uses sprintf()-like syntax. 506 * 507 * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string). 508 * Does not support sign, padding, alignment, width or precision specifiers. 509 * Does not support argument numbering/swapping. 510 * 511 * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}. 512 * 513 * Both %d and %s should be left unquoted in the query string. 514 * 515 * <code> 516 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 ) 517 * </code> 518 * 519 * @link http://php.net/sprintf Description of syntax. 508 520 * @since 2.3.0 509 521 * 510 * @param null|string $args If string, first parameter must be query statement 511 * @param mixed $args,... If additional parameters, they will be set inserted into the query. 522 * @param string $query Query statement with sprintf()-like placeholders 523 * @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()}. 524 * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}. 512 525 * @return null|string Sanitized query string 513 526 */ 514 function prepare($ args=null) {515 if ( is_null( $ args) )527 function prepare($query = null) { // ( $query, *$args ) 528 if ( is_null( $query ) ) 516 529 return; 517 530 $args = func_get_args(); 518 $query =array_shift($args);519 // If args were passed as an array , move them up531 array_shift($args); 532 // If args were passed as an array (as in vsprintf), move them up 520 533 if ( isset($args[0]) && is_array($args[0]) ) 521 534 $args = $args[0]; … … 638 651 * 639 652 * @param string $query 640 * @return unknown653 * @return int|false Number of rows affected/selected or false on error 641 654 */ 642 655 function query($query) { … … 708 721 709 722 /** 710 * Insert an array of data into a table. 723 * Insert a row into a table. 724 * 725 * <code> 726 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 727 * </code> 711 728 * 712 729 * @since 2.5.0 730 * @see wpdb::prepare() 713 731 * 714 732 * @param string $table table name 715 * @param array $data Should not already be SQL-escaped716 * @param array|string $format The format of the field values.717 * @return mixed Results of $this->query()733 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 734 * @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. 735 * @return int|false The number of rows inserted, or false on error. 718 736 */ 719 737 function insert($table, $data, $format = null) { … … 734 752 } 735 753 736 /** 737 * Update a row in the table with an array of data. 754 755 /** 756 * Update a row in the table 757 * 758 * <code> 759 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) ) 760 * </code> 738 761 * 739 762 * @since 2.5.0 763 * @see wpdb::prepare() 740 764 * 741 765 * @param string $table table name 742 * @param array $data Should not already be SQL-escaped743 * @param array $where A named array of WHERE c olumn => value relationships. Multiple member pairs will be joined with ANDs.744 * @param array|string $format The format of the field values.745 * @param array|string $ where_format The format of the where field values.746 * @return mixed Results of $this->query()766 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 767 * @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". 768 * @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. 769 * @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. 770 * @return int|false The number of rows updated, or false on error. 747 771 */ 748 772 function update($table, $data, $where, $format = null, $where_format = null) { … … 780 804 * Retrieve one variable from the database. 781 805 * 782 * This combines the functionality of wpdb::get_row() and wpdb::get_col(), 783 * so both the column and row can be picked. 784 * 785 * It is possible to use this function without executing more queries. If 786 * you already made a query, you can set the $query to 'null' value and just 787 * retrieve either the column and row of the last query result. 788 * 789 * @since 0.71 790 * 791 * @param string $query Can be null as well, for caching 792 * @param int $x Column num to return 793 * @param int $y Row num to return 794 * @return mixed Database query results 806 * Executes a SQL query and returns the value from the SQL result. 807 * 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. 808 * If $query is null, this function returns the value in the specified column and row from the previous SQL result. 809 * 810 * @since 0.71 811 * 812 * @param string|null $query SQL query. If null, use the result from the previous query. 813 * @param int $x (optional) Column of value to return. Indexed from 0. 814 * @param int $y (optional) Row of value to return. Indexed from 0. 815 * @return string Database query result 795 816 */ 796 817 function get_var($query=null, $x = 0, $y = 0) { … … 811 832 * Retrieve one row from the database. 812 833 * 813 * @since 0.71 814 * 815 * @param string $query SQL query 816 * @param string $output ARRAY_A | ARRAY_N | OBJECT 817 * @param int $y Row num to return 818 * @return mixed Database query results 834 * Executes a SQL query and returns the row from the SQL result. 835 * 836 * @since 0.71 837 * 838 * @param string|null $query SQL query. 839 * @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. 840 * @param int $y (optional) Row to return. Indexed from 0. 841 * @return mixed Database query result in format specifed by $output 819 842 */ 820 843 function get_row($query = null, $output = OBJECT, $y = 0) { … … 842 865 * Retrieve one column from the database. 843 866 * 844 * @since 0.71 845 * 846 * @param string $query Can be null as well, for caching 847 * @param int $x Col num to return. Starts from 0. 848 * @return array Column results 867 * Executes a SQL query and returns the column from the SQL result. 868 * If the SQL result contains more than one column, this function returns the column specified. 869 * If $query is null, this function returns the specified column from the previous SQL result. 870 * 871 * @since 0.71 872 * 873 * @param string|null $query SQL query. If null, use the result from the previous query. 874 * @param int $x Column to return. Indexed from 0. 875 * @return array Database query result. Array indexed from 0 by SQL result row number. 849 876 */ 850 877 function get_col($query = null , $x = 0) { … … 861 888 862 889 /** 863 * Retrieve an entire result set from the database. 864 * 865 * @since 0.71 866 * 867 * @param string|null $query Can also be null to pull from the cache 868 * @param string $output ARRAY_A | ARRAY_N | OBJECT_K | OBJECT 890 * Retrieve an entire SQL result set from the database (i.e., many rows) 891 * 892 * Executes a SQL query and returns the entire SQL result. 893 * 894 * @since 0.71 895 * 896 * @param string $query SQL query. 897 * @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. 869 898 * @return mixed Database query results 870 899 */ … … 937 966 * @since 1.5.0 938 967 * 939 * @return bool Always returnstrue968 * @return true 940 969 */ 941 970 function timer_start() { … … 962 991 963 992 /** 964 * Wraps fatal errors in a nice header and footer and dies. 993 * Wraps errors in a nice header and footer and dies. 994 * 995 * Will not die if wpdb::$show_errors is true 965 996 * 966 997 * @since 1.5.0 967 998 * 968 999 * @param string $message 969 * @return unknown1000 * @return false|void 970 1001 */ 971 1002 function bail($message) { … … 981 1012 982 1013 /** 983 * Whether or not MySQL database is minimal requiredversion.1014 * Whether or not MySQL database is at least the required minimum version. 984 1015 * 985 1016 * @since 2.5.0 … … 997 1028 998 1029 /** 999 * Whether of not the database versionsupports collation.1030 * Whether of not the database supports collation. 1000 1031 * 1001 1032 * Called when WordPress is generating the table scheme. … … 1013 1044 * Generic function to determine if a database supports a particular feature 1014 1045 * @param string $db_cap the feature 1015 * @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)1046 * @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. 1016 1047 * @return bool 1017 1048 */ … … 1064 1095 /** 1065 1096 * The database version number 1097 * @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. 1066 1098 * @return false|string false on failure, version number on success 1067 1099 */
Note: See TracChangeset
for help on using the changeset viewer.