站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
建站程序
开发
服务器
办公软件
开发教程
服务器教程
软件使用教程
运营教程
热门电子书
WordPress教程
宝塔面板教程
CSS教程
Shopify教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Function Reference/wpdb Class
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
== Interfacing With the Database == == Interfacing With the Database == WordPress provides a class of functions for all database manipulations. The class is called <code>wpdb</code> and is based on the [http://www.woyano.com/jv/ezsql ezSQL] class written and maintained by [http://www.jvmultimedia.com Justin Vincent]. Though the WordPress class is slightly different than the ezSQL class, their use is essentially the same. Please see the [http://justinvincent.com/docs/ezsql/ez_sql_help.htm ezSQL documentation] for more information. WordPress提供了一类函数,用于所有的数据库操作。这个class称为<code>wpdb</code>而且是以[http://www.woyano.com/jv/ezsql ezSQL] class为基础的,由[http://www.jvmultimedia.com Justin Vincent]编写和维护。虽然WordPress class与ezSQL class稍微不同,两者的用法本质山是相同的。更多的信息,请看看[http://justinvincent.com/docs/ezsql/ez_sql_help.htm ezSQL 文档]。 === Notes On Use === ===用法注意 === Within PHP code blocks in a [[WordPress:Templates|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 [[WordPress:Writing_a_Plugin#User_Interfaces|Writing a Plugin]] documentation. 在[[WordPress:Templates|模板]]中的PHP代码块内,$wpdb class应该如期望地那样运行,但是如果是插件或者外部脚本,可能有必要将其扩展到全局,再在代码中对其调用。这主要在[[WordPress:Writing_a_Plugin#User_Interfaces|编写插件]]文件中得到了解释。 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安装中创建的表格,就可以使用$wpdb class阅读数据库中任何表格中的数据,方式就如$wpdb class阅读WordPress安装的表格中的数据。查询的结构应该是"从mytable中,选择id, 名称",不要忧心从哪个数据库中查找表格,$wpdb object会自动地使用WordPress安装在的数据库。下面的任何函数,都会与这样设置的查询共同运行。 == query - Run Any Query on the Database == == 查询 – 在数据库中运行任何查询== The <code>query</code> function allows you to execute ''any'' query on the WordPress database. It is best to use a more specific function, however, for SELECT queries. <code>query</code>函数能够使你在WordPress数据库中执行''任何的''查询。最好为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 <code>wpdb</code> 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 <code>==</code> vs. identicality <code>===</code>). 如果有什么查询结果,函数会返回一个整数关于多少个组受到了影响而且查询结果会储存,让另一个<code>wpdb</code>函数使用。如果没有结果,函数会返回(int) 0。如果有MySQL错误,返回会返回错误的。('''注''':因为即可以返回0又可以返回错误的,确定你使用了正确的比较运算符:equality <code>==</code> vs. identicality <code>===</code>)。 Note: It is advisable to use the <code>wpdb->escape($user_entered_data_string)</code> 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. 注:建议使用<code>wpdb->escape($user_entered_data_string)</code>方法来保护数据库,免受不好的或者恶意的数据通过SQL袭击,特别是用户向数据库中输入数据使用插入或者更新SQL命令的时候。请看看下面标题为"躲避SQL 查询"这部分。 '''Additionally''', if you wish to access the database from your code file which is not placed inside one of the [http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations standard plugin locations], you will need to <code>include_once()</code> the <code>wp-db.php</code> file ''as well as'' the <code>wp-config.php</code> file. Including only the <code>wp-db.php</code> file will not set the database connection information resulting in an error message like "Wordpress could not connect to the database". '''此外''',如果你想要从代码文件中访问数据库,但是你的代码文件不在[http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations 标准的插件 locations],你就需要<code>include_once()</code> <code>wp-db.php</code>文件''和''<code>wp-config.php</code>文件。只包含<code>wp-db.php</code>文件不会设置数据库连接信息,反而会产生错误信息像"Wordpress 不能够连接到数据库"。 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 : 总是将函数放入插件中,是可取的。然而,有时候,如果你需要函数,可以使用这个workaround。例如,这是根/安装目录中的has_great_code.php的文件的代码。 <pre> include_once('wp-config.php'); include_once('wp-includes/wp-db.php'); </pre> <pre> include_once('wp-config.php'); include_once('wp-includes/wp-db.php'); </pre> === Examples === Add Post 13 to Category 2: === 例子=== 将第13篇文章添加到类别2: <pre> $wpdb->query(" INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES (13, 2)"); </pre> <pre> $wpdb->query(" INSERT INTO $wpdb->post2cat (post_id, category_id) VALUES (13, 2)"); </pre> Delete the 'gargle' meta key and value from Post 13. 从第十三篇文章中删除'gargle' meta key和参数值。 <pre> $wpdb->query(" DELETE FROM $wpdb->postmeta WHERE post_id = '13' AND meta_key = 'gargle'"); </pre> <pre> $wpdb->query(" DELETE FROM $wpdb->postmeta WHERE post_id = '13' AND meta_key = 'gargle'"); </pre> ''Performed in WordPress by <code>[[WordPress:Function Reference/delete post meta|delete_post_meta()]]</code>.'' ''在WordPress中由<code>[[WordPress:Function Reference/delete post meta|delete_post_meta()]]</code>执行。'' Set the parent of [[WordPress:Pages|Page]] 15 to Page 7. 将第15个[[WordPress:Pages|网页]]的母网页设置为网页7。 <pre> $wpdb->query(" UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = 'static'"); </pre> <pre> $wpdb->query(" UPDATE $wpdb->posts SET post_parent = 7 WHERE ID = 15 AND post_status = 'static'"); </pre> == get_var - SELECT a Variable == == get_var – 选择一个变数 == The <code>get_var</code> 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 <tt>NULL</tt> if no result is found. <code>get_var</code>函数返回数据库中的单一变数。虽然只返回了一个变数,查询的整个结果已经得到了储存,以便以后使用。如果没有找到结果,返回<tt>零</tt>。 %%% <?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 <code>null</code> will return the specified variable from the cached results of the previous query. ; query : (string)你想要运行的查询。将这个参数设置为<code>零</code>会返回先前查询所储存的结果中某个特别的变数。 ; column_offset : (integer) The desired column ('''0''' being the first). Defaults to '''0'''. ; column_offset : (integer)想得到的栏('''0''' 是第一个)。默认为'''0'''。 ; row_offset : (integer) The desired row ('''0''' being the first). Defaults to '''0'''. ; row_offset : (integer) (integer)想得到的组('''0''' 是第一个)。默认为'''0'''。 === Examples === Retrieve the name of Category 4. 返回类别4的名称。 === 例子 === <pre> $name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=4"); echo $name; </pre> <pre> $name = $wpdb->get_var("SELECT cat_name FROM $wpdb->categories WHERE cat_ID=4"); echo $name; </pre> Retrieve and display the number of users. 得到并且显示有多少名用户。 <pre> <?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?> <p><?php echo 'user count is ' . $user_count; ?></p> </pre> <pre> <?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;");?> <p><?php echo 'user count is ' . $user_count; ?></p> </pre> == get_row - SELECT a Row == == get_row – 选择一个组 == To retrieve an entire row from a query, use <code>get_row</code>. 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. 要得到查询中的整个组,请使用<code>get_row</code>。这个函数能够返回组作为object,一个相关的数据或者一个有限的数组。如果查询返回了多个组,函数只会返回特别的组,但是所有的组都会储存,便于以后使用。 %%% <?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 <code>null</code> will return the specified row from the cached results of the previous query. ; query : (string)你希望运行的查询。将这个参数设置为<code>零</code>会返回上一个查询中储存的某个组。 ; 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 :先前定义的三个常数中的一个。默认为OBJECT。 :* OBJECT –结果会作为object输出。 :* ARRAY_A –结果会作为结合的数组返回。 :* 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 –结果会作为有限的数组返回。 ; row_offset : (integer)想得到的组('''0'''是第一个)。默认为'''0'''。 === Examples === Get all the information about Link 10. === 例子 === 得到关于链接10的所有信息。 <pre> $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10"); </pre> <pre> $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10"); </pre> The properties of the <code>$mylink</code> object are the column names of the result from the SQL query (in this all of the columns from the <code>$wpdb->links</code> table). echo $mylink->link_id; // prints "10" <code>$mylink</code> object的属性是从SQL查询中返回的结果的栏名称(在这里,是<code>$wpdb->links</code>表格中的所有的栏)。 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 <code>get_col</code>. 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. 要选择一栏,请使用<code>get_col</code>。这个函数输出多维数组。如果查询返回了几个栏,函数只会返回某个特别的栏,但是整个结果会得到保存,以便于下次使用。 %%% <?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 <code>null</code> 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)你想要执行的查询。将这个参数设置为<code>零</code>会返回先前的查询保存的结果中的某个栏。 ; column_offset : (integer) 想要的栏 ('''0''' 是第一个)默认为 '''0'''。 === Examples === Get all the Categories to which Post 103 belongs. === 例子 === 得到第103篇文章所属于的所有的类别。 <pre> $postcats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = 103 ORDER BY category_id"); </pre> <pre> $postcats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = 103 ORDER BY category_id"); </pre> ''Performed in WordPress by <code>[[WordPress:Function Reference/wp get post cats|wp_get_post_cats()]]</code>.'' ''在WordPress中由<code>[[WordPress:Function Reference/wp get post cats|wp_get_post_cats()]]</code>执行。'' == get_results - SELECT Generic Results == == get_results – 选择一般结果 == Generic, mulitple row results can be pulled from the database with <code>get_results</code>. 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 <code>get_row</code> can be an object, an associative array, or a numbered array. 一般的,多个组结果可以使用<code>get_results</code>,从数据库中得到。函数返回整个查询作为一个数组。这个数组中的每个元素与查询结果中的一组相对应,如<code>get_row</code>可以是个object,一个结合的数组或者有限的数组。 %%% <?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 <code>null</code> 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)你想要运行的查询。将这个参数设置为<code>零</code>会返回先前查询结果保存的数据。 ; output_type :三个先前定义的常数中的一个。默认为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 –输出结果作为object。 :* ARRAY_N -输出结果作为有限的数组。 :* ARRAY_ -输出结果作为结合的数组。 === Examples === Get the IDs and Titles of all the Drafts by User 5 and echo the Titles. === 例子 === 得到第5个的所有草稿的IDs和标题并且echo标题。 <pre> $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; } </pre> <pre> $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; } </pre> 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 标题。(例子在WordPress2.2.1版本中能够运行) <pre> <?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; ?> </pre> <pre> <?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 = '发表' 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; ?> </pre> == prepare - Protect Your SQL Queries Against SQL Injection Attacks == == 准备 – 保护你的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 <code>prepare</code> method. 如果你正创建一个SQL查询,确定你能够免受SQL injection的袭击。使用<code>prepare</code>方法,能够轻易地做到实现保护。 %%%<?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 <code>stripslashes()</code> when loading data back into WordPress that was inserted with a prepared query. 注,WordPress插入了先前的查询,你想将数据载入,返回WordPress,你可能需要使用PHP的<code>stripslashes()</code>。 ===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'数据库界面就像星期天的早晨:简单。"到第十篇文章。 <pre> $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 ) ); </pre> <pre> $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 ) ); </pre> ''Performed in WordPress by <code>add_meta()</code>.'' ''由 <code>add_meta()</code>在WordPress中执行。'' Notice that you do not have to worry about quoting strings. Instead of passing the variables directly into the SQL query, place a <code>%s</code> marker for strings and a <code>%d</code> marker for integers. You can pass as many values as you like, each as a new parameter in the <code>prepare()</code> method. 注意你不需要担心引入的字符串问题。不要将变数直接传递到SQL查询,为字符串加上标记<code>%s</code>,为整数加上标记<code>%d</code>。你想传递多少参数值,就可以传递多少参数值,每个参数值,都是<code>prepare()</code> method中的一个新参数。 == show/hide_errors - Show and Hide SQL Errors == == show/hide_errors – 显示和隐藏SQL错误 == You can turn error echoing on and off with the <code>show_errors</code> and <code>hide_errors</code>, respectively. 你可以分别使用<code>show_errors</code>和<code>hide_errors</code>,打开和关闭错误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 <code>print_error</code>. 你也可以打印出大多数最近的查询<code>print_error</code>的错误(如果有这个错误的话)。 %%% <?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 <code>get_col_info</code>. 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. 你可以得到最近的<code>get_col_info</code>查询结果的栏信息。当函数返回一个OBJECT,但是你不知道这个OBJECT的属性的时候,得到了栏信息,就很有用。这个函数会从某个栏中输出你想要的信息,或者如果没有规定栏,函数会返回数组,关于查询结果中''所有的''栏的信息。 %%% <?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 [http://justinvincent.com/home/docs/ezsql/ez_sql_help.htm ezSQL docs]). Defaults to '''name'''. :*name - column name. Default. :*name –栏名称。默认。 ; type : (string)你想要得到什么信息。可能会获得以下任何参数值(列表从[http://justinvincent.com/home/docs/ezsql/ez_sql_help.htm ezSQL docs]中得到)。默认为'''名称'''。 :*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如果栏是数字的 :*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''' 代表第一个栏)。默认为'''-1'''。 :*-1 - Retrieve information from all columns. Output as array. Default. :*-1 –返回所有栏中得到的信息。作为数组输出。默认。 :*Non-negative integer - Retrieve information from specified column ('''0''' being the first). :*非负数的整数 –返回某个特别的栏中的信息('''0''' 代表第一个栏)。 == flush - Clearing the Cache == == flush –清除缓存== You can clear the SQL result cache with <code>flush</code>. 你可以使用<code>flush</code>清除SQL结果缓存。 %%% <?php $wpdb->flush(); ?> %%% %%% <?php $wpdb->flush(); ?> %%% This clears <code>$wpdb->last_result</code>, <code>$wpdb->last_query</code>, and <code>$wpdb->col_info</code>. 这清除了<code>$wpdb->last_result</code>, <code>$wpdb->last_query</code>, 和<code>$wpdb->col_info</code>。 == Class Variables == == Class 变数== ; $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]]是否打开了。默认为正确的。 ; $num_queries : The number of queries that have been executed. ; $num_queries :已经执行的查询的数目。 ; $last_query : The most recent query to have been executed. ; $last_query :已经执行的最近的查询。 ; $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 :你可以保存数据库中运行的所有查询并且查询结束时间设置为SAVEQUERIES常数为正确的(这个常数默认为错误的)。如果SAVEQUERIES是正确的,你的查询就会作为数组在这个变数中查询。 ; $last_results : The most recent query results. ; $last_results :最近的查询结果。 ; $col_info : The column information for the most recent query results. See [[WordPress:#Getting Column Information|Getting Column Information]]. ; $col_info :最近的查询结果的栏信息。请看看[[WordPress:#Getting Column Information|得到栏信息]]。 ; $insert_id : ID generated for an AUTO_INCREMENT column by the most recent INSERT query. ; $insert_id :最近的插入查询的AUTO_INCREMENT栏产生的ID。 == Tables == == 表格 == <!-- will likely not be useful when the database structure is fully described --> <!—当数据库结构得到完全描述的时候,可能没有用--> The WordPress database tables are easily referenced in the <code>wpdb</code> class. 在<code>wpdb</code> class中能够轻易地参考WordPress数据库表格。 ; $posts : The table of [[WordPress:Database Description#Table:_wp_posts|Posts]]. ; $posts : [[WordPress:Database Description#Table:_wp_posts|文章]]表格。 ; $users : The table of [[WordPress:Database Description#Table:_wp_users|Users]]. ; $users : [[WordPress:Database Description#Table:_wp_users|用户]]表格。 ; $comments : The [[WordPress:Database Description#Table:_wp_comments|Comments]] table. ; $comments : [[WordPress:Database Description#Table:_wp_comments|评论]] 表格。 ; $links : The table of [[WordPress:Database Description#Table:_wp_links|Links]]. ; $links : The table of [[WordPress:Database Description#Table:_wp_links|链接]]表格。 ; $options : The [[WordPress:Database Description#Table:_wp_options|Options]] table. ; $options : [[WordPress:Database Description#Table:_wp_options|选项]]表格。 ; $postmeta : The [[WordPress:Database Description#Table:_wp_postmeta|Meta Content]] (a.k.a. [[WordPress:Using Custom Fields|Custom Fields]]) table. ; $postmeta : [[WordPress:Database Description#Table:_wp_postmeta|Meta 内容]] (又名[[WordPress:Using Custom Fields|自定义区]])表格。 ; $usermeta : The [[WordPress:Database Description#Table:_wp_usermeta|usermeta]] table contains additional user information, such as nicknames, descriptions and permissions. ; $usermeta : [[WordPress:Database Description#Table:_wp_usermeta|usermeta]]表格包含有用户的额外信息,例如昵称,描述,和权限。 ; $terms : The [[WordPress:Database Description#Table:_wp_terms|terms]] table contains the 'description' of Categories, Link Categories, Tags. ; $terms : [[WordPress:Database Description#Table:_wp_terms|术语]]表格包含有类别,链接类别,标签的'描述'。 ; $term_taxonomy : The [[WordPress:Database Description#Table:_wp_term_taxonomy|term_taxonomy]] table describes the various taxonomies (classes of terms). Categories, Link Categories, and Tags are taxonomies. ; $term_taxonomy : [[WordPress:Database Description#Table:_wp_term_taxonomy|term_taxonomy]]表格描述了不同的分类法(术语的分类)。类别,链接类别,和标签都是分类的。 ; $term_relationships : The [[WordPress:Database Description#Table:_wp_term_relationships|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 [[WordPress:Database Description#Table:_wp_term_relationships|术语关系表格]]包含术语和使用这个术语的object之间的关系,指的是这个文件指向每篇文章所使用的类别。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)