WIKI使用導(dǎo)航
站長百科導(dǎo)航
站長專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計算
- 微博營銷
- 虛擬主機管理系統(tǒng)
- 開放平臺
- WIKI程序與應(yīng)用
- 美國十大主機
WordPress:Function Reference/wpdb Class
Interfacing With the Database[ ]
Interfacing With the Database[ ]
WordPress provides a class of functions for all database manipulations. The class is called wpdb
and is based on the ezSQL class written and maintained by Justin Vincent. Though the WordPress class is slightly different than the ezSQL class, their use is essentially the same. Please see the ezSQL documentation for more information.
WordPress提供了一類函數(shù),用于所有的數(shù)據(jù)庫操作。這個class稱為wpdb
而且是以ezSQL class為基礎(chǔ)的,由Justin Vincent編寫和維護。雖然WordPress class與ezSQL class稍微不同,兩者的用法本質(zhì)山是相同的。更多的信息,請看看ezSQL 文檔。
Notes On Use[ ]
用法注意[ ]
Within PHP code blocks in a template the $wpdb class should work as expected, but in the case of a plugin or external script it may be necessary to scope it to global before calling it in your code. This is briefly explained in the Writing a Plugin documentation.
在模板中的PHP代碼塊內(nèi),$wpdb class應(yīng)該如期望地那樣運行,但是如果是插件或者外部腳本,可能有必要將其擴展到全局,再在代碼中對其調(diào)用。這主要在編寫插件文件中得到了解釋。
If writing a plugin that will use a table that is not created in a vanilla WordPress installation, the $wpdb class can be used to read data from any table in the database in much the same way it can read data from a WordPress-Installed table. The query should be structured like "SELECT id, name FROM mytable", don't worry about specifying which database to look for the table in, the $wpdb object will automatically use the database WordPress is installed in. Any of the functions below will work with a query that is set up like this.
如果編寫一個插件,使用的表格,不是普通WordPress安裝中創(chuàng)建的表格,就可以使用$wpdb class閱讀數(shù)據(jù)庫中任何表格中的數(shù)據(jù),方式就如$wpdb class閱讀WordPress安裝的表格中的數(shù)據(jù)。查詢的結(jié)構(gòu)應(yīng)該是"從mytable中,選擇id, 名稱",不要憂心從哪個數(shù)據(jù)庫中查找表格,$wpdb object會自動地使用WordPress安裝在的數(shù)據(jù)庫。下面的任何函數(shù),都會與這樣設(shè)置的查詢共同運行。
query - Run Any Query on the Database[ ]
查詢 – 在數(shù)據(jù)庫中運行任何查詢[ ]
The query
function allows you to execute any query on the WordPress database. It is best to use a more specific function, however, for SELECT queries.
query
函數(shù)能夠使你在WordPress數(shù)據(jù)庫中執(zhí)行任何的查詢。最好為SELECT查詢使用更確切的查詢:
%%% <?php $wpdb->query('query'); ?> %%%
- query
- (string) The query you wish to run.
%%% <?php $wpdb->query('query'); ?> %%%
- query
- (string) 你希望運行的查詢。
If there are any query results, the function will return an integer corresponding to the number of rows affected and the query results will cached for use by other wpdb
functions. If there are no results, the function will return (int) 0. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and FALSE can be returned, make sure you use the correct comparison operator: equality ==
vs. identicality ===
).
如果有什么查詢結(jié)果,函數(shù)會返回一個整數(shù)關(guān)于多少個組受到了影響而且查詢結(jié)果會儲存,讓另一個wpdb
函數(shù)使用。如果沒有結(jié)果,函數(shù)會返回(int) 0。如果有MySQL錯誤,返回會返回錯誤的。(注:因為即可以返回0又可以返回錯誤的,確定你使用了正確的比較運算符:equality ==
vs. identicality ===
)。
Note: It is advisable to use the wpdb->escape($user_entered_data_string)
method to protect the database against SQL injection attacks by malformed or malicious data, especially when using the INSERT or UPDATE SQL commands on user-entered data in the database. See the section entitled "Escape for SQL Queries" below.
注:建議使用wpdb->escape($user_entered_data_string)
方法來保護數(shù)據(jù)庫,免受不好的或者惡意的數(shù)據(jù)通過SQL襲擊,特別是用戶向數(shù)據(jù)庫中輸入數(shù)據(jù)使用插入或者更新SQL命令的時候。請看看下面標(biāo)題為"躲避SQL 查詢"這部分。
Additionally, if you wish to access the database from your code file which is not placed inside one of the standard plugin locations, you will need to include_once()
the wp-db.php
file as well as the wp-config.php
file. Including only the wp-db.php
file will not set the database connection information resulting in an error message like "Wordpress could not connect to the database".
此外,如果你想要從代碼文件中訪問數(shù)據(jù)庫,但是你的代碼文件不在標(biāo)準(zhǔn)的插件 locations,你就需要include_once()
wp-db.php
文件和wp-config.php
文件。只包含wp-db.php
文件不會設(shè)置數(shù)據(jù)庫連接信息,反而會產(chǎn)生錯誤信息像"Wordpress 不能夠連接到數(shù)據(jù)庫"。
It is always advisable to put your functionality inside a plugin. However, if you need it in some cases, this workaround is available.
For example, this is the code in a file has_great_code.php in the root/installation directory :
總是將函數(shù)放入插件中,是可取的。然而,有時候,如果你需要函數(shù),可以使用這個workaround。例如,這是根/安裝目錄中的has_great_code.php的文件的代碼。
include_once('wp-config.php'); include_once('wp-includes/wp-db.php');
include_once('wp-config.php'); include_once('wp-includes/wp-db.php');
Examples[ ]
Add Post 13 to Category 2:
例子[ ]
將第13篇文章添加到類別2:
$wpdb->query(" INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES (13, 2)");
$wpdb->query(" INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES (13, 2)");
Delete the 'gargle' meta key and value from Post 13.
從第十三篇文章中刪除'gargle' meta key和參數(shù)值。
$wpdb->query(" DELETE FROM $wpdb->postmeta WHERE post_id = '13' AND meta_key = 'gargle'");
$wpdb->query(" DELETE FROM $wpdb->postmeta WHERE post_id = '13' AND meta_key = 'gargle'");
Performed in WordPress by delete_post_meta()
.
在WordPress中由delete_post_meta()
執(zhí)行。
Set the parent of Page 15 to Page 7.
將第15個網(wǎng)頁的母網(wǎng)頁設(shè)置為網(wǎng)頁7。
$wpdb->query(" UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = 'static'");
$wpdb->query(" UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = 'static'");
get_var - SELECT a Variable[ ]
get_var – 選擇一個變數(shù)[ ]
The get_var
function returns a single variable from the database. Though only one variable is returned, the entire result of the query is cached for later use. Returns NULL if no result is found.
get_var
函數(shù)返回數(shù)據(jù)庫中的單一變數(shù)。雖然只返回了一個變數(shù),查詢的整個結(jié)果已經(jīng)得到了儲存,以便以后使用。如果沒有找到結(jié)果,返回零。
%%% <?php $wpdb->get_var('query',column_offset,row_offset); ?> %%% %%% <?php $wpdb->get_var('query',column_offset,row_offset); ?> %%%
- query
- (string) The query you wish to run. Setting this parameter to
null
will return the specified variable from the cached results of the previous query.
- query
- (string)你想要運行的查詢。將這個參數(shù)設(shè)置為
零
會返回先前查詢所儲存的結(jié)果中某個特別的變數(shù)。
- column_offset
- (integer) The desired column (0 being the first). Defaults to 0.
- column_offset
- (integer)想得到的欄(0 是第一個)。默認(rèn)為0。
- row_offset
- (integer) The desired row (0 being the first). Defaults to 0.
- row_offset
- (integer) (integer)想得到的組(0 是第一個)。默認(rèn)為0。
Examples[ ]
Retrieve the name of Category 4.
返回類別4的名稱。
例子[ ]
$name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=4"); echo $name;
$name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=4"); echo $name;
Retrieve and display the number of users. 得到并且顯示有多少名用戶。
<?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?> <p><?php echo 'user count is ' . $user_count; ?></p>
<?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?> <p><?php echo 'user count is ' . $user_count; ?></p>
get_row - SELECT a Row[ ]
get_row – 選擇一個組[ ]
To retrieve an entire row from a query, use get_row
. The function can return the row as an object, an associative array, or as a numbered array. If more than one row is returned by the query, only the specified row is returned by the function, but all rows are cached for later use.
要得到查詢中的整個組,請使用get_row
。這個函數(shù)能夠返回組作為object,一個相關(guān)的數(shù)據(jù)或者一個有限的數(shù)組。如果查詢返回了多個組,函數(shù)只會返回特別的組,但是所有的組都會儲存,便于以后使用。
%%% <?php $wpdb->get_row('query', output_type, row_offset); ?> %%%
%%% <?php $wpdb->get_row('query', output_type, row_offset); ?> %%%
- query
- (string) The query you wish to run. Setting this parameter to
null
will return the specified row from the cached results of the previous query. - query
- (string)你希望運行的查詢。將這個參數(shù)設(shè)置為
零
會返回上一個查詢中儲存的某個組。
- output_type
- One of three pre-defined constants. Defaults to OBJECT.
- OBJECT - result will be output as an object.
- ARRAY_A - result will be output as an associative array.
- output_type
- 先前定義的三個常數(shù)中的一個。默認(rèn)為OBJECT。
- OBJECT –結(jié)果會作為object輸出。
- ARRAY_A –結(jié)果會作為結(jié)合的數(shù)組返回。
- ARRAY_N - result will be output as a numbered array.
- row_offset
- (integer) The desired row (0 being the first). Defaults to 0.
- ARRAY_N –結(jié)果會作為有限的數(shù)組返回。
- row_offset
- (integer)想得到的組(0是第一個)。默認(rèn)為0。
Examples[ ]
Get all the information about Link 10.
例子[ ]
得到關(guān)于鏈接10的所有信息。
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10");
The properties of the $mylink
object are the column names of the result from the SQL query (in this all of the columns from the $wpdb->links
table).
echo $mylink->link_id; // prints "10"
$mylink
object的屬性是從SQL查詢中返回的結(jié)果的欄名稱(在這里,是$wpdb->links
表格中的所有的欄)。
echo $mylink->link_id; // prints "10"
In contrast, using
與此相反,使用
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A);
would result in an associative array:
echo $mylink['link_id']; // prints "10"
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A);
would result in an associative array:
echo $mylink['link_id']; // prints "10"
and
和
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N);
would result in a numbered array:
echo $mylink[1]; // prints "10"
$mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N); would result in a numbered array:
echo $mylink[1]; // prints "10"
get_col - SELECT a Column[ ]
get_col – 選擇一個欄[ ]
To SELECT a column, use get_col
. This function outputs a dimensional array. If more than one column is returned by the query, only the specified column will be returned by the function, but the entire result is cached for later use.
要選擇一欄,請使用get_col
。這個函數(shù)輸出多維數(shù)組。如果查詢返回了幾個欄,函數(shù)只會返回某個特別的欄,但是整個結(jié)果會得到保存,以便于下次使用。
%%% <?php $wpdb->get_col('query',column_offset); ?> %%%
%%% <?php $wpdb->get_col('query',column_offset); ?> %%%
- query
- (string) the query you wish to execute. Setting this parameter to
null
will return the specified column from the cached results of the previous query. - column_offset
- (integer) The desired column (0 being the first). Defaults to 0.
- query
- (string)你想要執(zhí)行的查詢。將這個參數(shù)設(shè)置為
零
會返回先前的查詢保存的結(jié)果中的某個欄。
- column_offset
- (integer) 想要的欄 (0 是第一個)默認(rèn)為 0。
Examples[ ]
Get all the Categories to which Post 103 belongs.
例子[ ]
得到第103篇文章所屬于的所有的類別。
$postcats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = 103 ORDER BY category_id");
$postcats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = 103 ORDER BY category_id");
Performed in WordPress by wp_get_post_cats()
.
在WordPress中由wp_get_post_cats()
執(zhí)行。
get_results - SELECT Generic Results[ ]
get_results – 選擇一般結(jié)果[ ]
Generic, mulitple row results can be pulled from the database with get_results
. The function returns the entire query result as an array. Each element of this array corresponds to one row of the query result and, like get_row
can be an object, an associative array, or a numbered array.
一般的,多個組結(jié)果可以使用get_results
,從數(shù)據(jù)庫中得到。函數(shù)返回整個查詢作為一個數(shù)組。這個數(shù)組中的每個元素與查詢結(jié)果中的一組相對應(yīng),如get_row
可以是個object,一個結(jié)合的數(shù)組或者有限的數(shù)組。
%%% <?php $wpdb->get_results('query', output_type); ?> %%%
%%% <?php $wpdb->get_results('query', output_type); ?> %%%
- query
- (string) The query you wish to run. Setting this parameter to
null
will return the data from the cached results of the previous query. - output_type
- One of three pre-defined constants. Defaults to OBJECT. See [[WordPress:#SELECT a Row|SELECT a Row]] and its examples for more information.
- query
- (string)你想要運行的查詢。將這個參數(shù)設(shè)置為
零
會返回先前查詢結(jié)果保存的數(shù)據(jù)。 - output_type
- 三個先前定義的常數(shù)中的一個。默認(rèn)為OBJECT。請看看[[WordPress:#SELECT a Row|選擇一個組]]以及例子,得到更多的信息。
- OBJECT - result will be output as an object.
- ARRAY_A - result will be output as an associative array.
- ARRAY_N - result will be output as a numbered array.
- OBJECT –輸出結(jié)果作為object。
- ARRAY_N -輸出結(jié)果作為有限的數(shù)組。
- ARRAY_ -輸出結(jié)果作為結(jié)合的數(shù)組。
Examples[ ]
Get the IDs and Titles of all the Drafts by User 5 and echo the Titles.
例子[ ]
得到第5個的所有草稿的IDs和標(biāo)題并且echo標(biāo)題。
$fivesdrafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = 5"); foreach ($fivesdrafts as $fivesdraft) { echo $fivesdraft->post_title; }
$fivesdrafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = 5"); foreach ($fivesdrafts as $fivesdraft) { echo $fivesdraft->post_title; }
Using the OBJECT output_type, get the 5 most recent posts in Categories 3,20, and 21 and display the permalink title to each post. (example works at WordPress Version 2.2.1)
使用OBJECT output_type,得到類別3,20,和21的最近五篇文章并且顯示每篇文章的permalink 標(biāo)題。(例子在WordPress2.2.1版本中能夠運行)
<?php $querystr =" SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' AND $wpdb->post2cat.category_id IN (3,20,21) ORDER BY $wpdb->posts.post_date DESC LIMIT 5"; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <?php endforeach; ?> <?php else : ?> <h2> Not Found</h2> <?php endif; ?>
<?php $querystr =" SELECT $wpdb->posts.* FROM $wpdb->posts LEFT JOIN $wpdb->post2cat ON ($wpdb->posts.ID = $wpdb->post2cat.post_id) WHERE $wpdb->posts.post_status = '發(fā)表' AND $wpdb->posts.post_type = '文章' AND $wpdb->post2cat.category_id IN (3,20,21) ORDER BY $wpdb->posts.post_date DESC LIMIT 5"; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?php if ($pageposts): ?> <?php foreach ($pageposts as $post): ?> <?php setup_postdata($post); ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"> <?php the_title(); ?></a></h2> <?php endforeach; ?> <?php else : ?> <h2>沒有找到</h2> <?php endif; ?>
prepare - Protect Your SQL Queries Against SQL Injection Attacks[ ]
準(zhǔn)備 – 保護你的SQL 查詢免受SQL Injection攻擊[ ]
If you're creating an SQL query, make sure you protect against SQL injection attacks. This can be conveniently done with the prepare
method.
如果你正創(chuàng)建一個SQL查詢,確定你能夠免受SQL injection的襲擊。使用prepare
方法,能夠輕易地做到實現(xiàn)保護。
%%%<?php $sql = $wpdb->prepare( 'query'[, value_parameter, value_parameter ... ] ); ?>%%%
%%%<?php $sql = $wpdb->prepare( 'query'[, value_parameter, value_parameter ... ] ); ?>%%%
Note that you may need to use PHP's stripslashes()
when loading data back into WordPress that was inserted with a prepared query.
注,WordPress插入了先前的查詢,你想將數(shù)據(jù)載入,返回WordPress,你可能需要使用PHP的stripslashes()
。
Examples[ ]
Add Meta key => value pair "Harriet's Adages" => "WordPress' database interface is like Sunday Morning: Easy." to Post 10.
例子[ ]
添加Meta key => value pair "Harriet's Adages" => "WordPress'數(shù)據(jù)庫界面就像星期天的早晨:簡單。"到第十篇文章。
$metakey = "Harriet's Adages"; $metavalue = "WordPress' database interface is like Sunday Morning: Easy."; $wpdb->query( $wpdb->prepare( " INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", 10, $metakey, $metavalue ) );
$metakey = "Harriet's Adages"; $metavalue = "WordPress' database interface is like Sunday Morning: Easy."; $wpdb->query( $wpdb->prepare( " INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", 10, $metakey, $metavalue ) );
Performed in WordPress by add_meta()
.
由 add_meta()
在WordPress中執(zhí)行。
Notice that you do not have to worry about quoting strings. Instead of passing the variables directly into the SQL query, place a %s
marker for strings and a %d
marker for integers. You can pass as many values as you like, each as a new parameter in the prepare()
method.
注意你不需要擔(dān)心引入的字符串問題。不要將變數(shù)直接傳遞到SQL查詢,為字符串加上標(biāo)記%s
,為整數(shù)加上標(biāo)記%d
。你想傳遞多少參數(shù)值,就可以傳遞多少參數(shù)值,每個參數(shù)值,都是prepare()
method中的一個新參數(shù)。
show/hide_errors - Show and Hide SQL Errors[ ]
show/hide_errors – 顯示和隱藏SQL錯誤[ ]
You can turn error echoing on and off with the show_errors
and hide_errors
, respectively.
你可以分別使用show_errors
和hide_errors
,打開和關(guān)閉錯誤echoing。
%%% <?php $wpdb->show_errors(); ?> <?php $wpdb->hide_errors(); ?> %%%
%%% <?php $wpdb->show_errors(); ?> <?php $wpdb->hide_errors(); ?> %%%
You can also print the error (if any) generated by the most recent query with print_error
.
你也可以打印出大多數(shù)最近的查詢print_error
的錯誤(如果有這個錯誤的話)。
%%% <?php $wpdb->print_error(); ?> %%%
%%% <?php $wpdb->print_error(); ?> %%%
get_col_info - Getting Column Information[ ]
get_col_info – 得到欄信息[ ]
You can retrieve information about the columns of the most recent query result with get_col_info
. This can be useful when a function has returned an OBJECT whose properties you don't know. The function will output the desired information from the specified column, or an array with information on all columns from the query result if no column is specified.
你可以得到最近的get_col_info
查詢結(jié)果的欄信息。當(dāng)函數(shù)返回一個OBJECT,但是你不知道這個OBJECT的屬性的時候,得到了欄信息,就很有用。這個函數(shù)會從某個欄中輸出你想要的信息,或者如果沒有規(guī)定欄,函數(shù)會返回數(shù)組,關(guān)于查詢結(jié)果中所有的欄的信息。
%%% <?php $wpdb->get_col_info('type', offset); ?> %%%
%%% <?php $wpdb->get_col_info('type', offset); ?> %%%
- type
- (string) What information you wish to retrieve. May take on any of the following values (list taken from the ezSQL docs). Defaults to name.
- name - column name. Default.
- name –欄名稱。默認(rèn)。
- type
- (string)你想要得到什么信息??赡軙@得以下任何參數(shù)值(列表從ezSQL docs中得到)。默認(rèn)為名稱。
- table - name of the table the column belongs to
- max_length - maximum length of the column
- not_null - 1 if the column cannot be NULL
- primary_key - 1 if the column is a primary key
- table-欄所屬于的某個表格的名稱
- max_length –欄的最長長度
- not_null -1如果欄不能是零
- primary_key – 1如果欄是個primary key
- unique_key - 1 if the column is a unique key
- unique_key – 1如果欄是個unique key
- multiple_key - 1 if the column is a non-unique key
- multiple_key – 1如果欄是個非唯一的key
- numeric - 1 if the column is numeric
- numeric – 1如果欄是數(shù)字的
- blob - 1 if the column is a BLOB
- blob – 1如果欄是個BLOB
- type - the type of the column
- type –欄的類型
- unsigned - 1 if the column is unsigned
- unsigned – 1如果欄沒有符號
- zerofill - 1 if the column is zero-filled
- zerofill – 1如果欄是zero-filled
- offset
- (integer) Specify the column from which to retrieve information (with 0 being the first column). Defaults to -1.
- offset
- (integer)指定從哪個欄中得到信息(0 代表第一個欄)。默認(rèn)為-1。
- -1 - Retrieve information from all columns. Output as array. Default.
- -1 –返回所有欄中得到的信息。作為數(shù)組輸出。默認(rèn)。
- Non-negative integer - Retrieve information from specified column (0 being the first).
- 非負(fù)數(shù)的整數(shù) –返回某個特別的欄中的信息(0 代表第一個欄)。
flush - Clearing the Cache[ ]
flush –清除緩存[ ]
You can clear the SQL result cache with flush
.
你可以使用flush
清除SQL結(jié)果緩存。
%%% <?php $wpdb->flush(); ?> %%%
%%% <?php $wpdb->flush(); ?> %%%
This clears $wpdb->last_result
, $wpdb->last_query
, and $wpdb->col_info
.
這清除了$wpdb->last_result
, $wpdb->last_query
, 和$wpdb->col_info
。
Class Variables[ ]
Class 變數(shù)[ ]
- $show_errors
- Whether or not [[WordPress:#Showing and Hiding SQL Errors|Error echoing]] is turned on. Defaults to TRUE.
- $show_errors
- [[WordPress:#Showing and Hiding SQL Errors|錯誤 echoing]]是否打開了。默認(rèn)為正確的。
- $num_queries
- The number of queries that have been executed.
- $num_queries
- 已經(jīng)執(zhí)行的查詢的數(shù)目。
- $last_query
- The most recent query to have been executed.
- $last_query
- 已經(jīng)執(zhí)行的最近的查詢。
- $queries
- You may save all of the queries run on the database and their stop times be setting the SAVEQUERIES constant to TRUE (this constant defaults to FALSE). If SAVEQUERIES is TRUE, your queries will be stored in this variable as an array.
- $queries
- 你可以保存數(shù)據(jù)庫中運行的所有查詢并且查詢結(jié)束時間設(shè)置為SAVEQUERIES常數(shù)為正確的(這個常數(shù)默認(rèn)為錯誤的)。如果SAVEQUERIES是正確的,你的查詢就會作為數(shù)組在這個變數(shù)中查詢。
- $last_results
- The most recent query results.
- $last_results
- 最近的查詢結(jié)果。
- $col_info
- The column information for the most recent query results. See [[WordPress:#Getting Column Information|Getting Column Information]].
- $col_info
- 最近的查詢結(jié)果的欄信息。請看看[[WordPress:#Getting Column Information|得到欄信息]]。
- $insert_id
- ID generated for an AUTO_INCREMENT column by the most recent INSERT query.
- $insert_id
- 最近的插入查詢的AUTO_INCREMENT欄產(chǎn)生的ID。
Tables[ ]
表格[ ]
<!—當(dāng)數(shù)據(jù)庫結(jié)構(gòu)得到完全描述的時候,可能沒有用-->
The WordPress database tables are easily referenced in the wpdb
class.
在wpdb
class中能夠輕易地參考WordPress數(shù)據(jù)庫表格。
- $posts
- The table of Posts.
- $posts
- 文章表格。
- $users
- The table of Users.
- $users
- 用戶表格。
- $comments
- The Comments table.
- $comments
- 評論 表格。
- $links
- The table of Links.
- $links
- The table of 鏈接表格。
- $options
- The Options table.
- $options
- 選項表格。
- $postmeta
- The Meta Content (a.k.a. Custom Fields) table.
- $postmeta
- Meta 內(nèi)容 (又名自定義區(qū))表格。
- $usermeta
- The usermeta table contains additional user information, such as nicknames, descriptions and permissions.
- $usermeta
- usermeta表格包含有用戶的額外信息,例如昵稱,描述,和權(quán)限。
- $terms
- The terms table contains the 'description' of Categories, Link Categories, Tags.
- $terms
- 術(shù)語表格包含有類別,鏈接類別,標(biāo)簽的'描述'。
- $term_taxonomy
- The term_taxonomy table describes the various taxonomies (classes of terms). Categories, Link Categories, and Tags are taxonomies.
- $term_taxonomy
- term_taxonomy表格描述了不同的分類法(術(shù)語的分類)。類別,鏈接類別,和標(biāo)簽都是分類的。
- $term_relationships
- The term relationships table contains link between the term and the object that uses that term, meaning this file point to each Category used for each Post.
- $term_relationships
- The 術(shù)語關(guān)系表格包含術(shù)語和使用這個術(shù)語的object之間的關(guān)系,指的是這個文件指向每篇文章所使用的類別。