站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
建站程序
开发
服务器
办公软件
开发教程
服务器教程
软件使用教程
运营教程
热门电子书
WordPress教程
宝塔面板教程
CSS教程
Shopify教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
Function Reference/wpdb Class
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
切换编辑器
您已切换至源代码编辑
关闭
您可以随时通过点击该图标切换回可视化编辑。
可视化编辑
源代码编辑
更多
高级
特殊字符
帮助
标题
2级
3级
4级
5级
格式
插入
拉丁字母
扩展拉丁字母
国际音标
符号
希腊字母
希腊字母扩展
西里尔字母
阿拉伯字母
扩展阿拉伯字母
希伯来字母
孟加拉语字符集
泰米尔数字和符号
泰卢固语字符集
僧伽罗语字符集
梵文字符集
古吉拉特语字符集
泰语字符集
老挝语
高棉语字母
加拿大原住民音节文字
卢恩
Á
á
À
à
Â
â
Ä
ä
Ã
ã
Ǎ
ǎ
Ā
ā
Ă
ă
Ą
ą
Å
å
Ć
ć
Ĉ
ĉ
Ç
ç
Č
č
Ċ
ċ
Đ
đ
Ď
ď
É
é
È
è
Ê
ê
Ë
ë
Ě
ě
Ē
ē
Ĕ
ĕ
Ė
ė
Ę
ę
Ĝ
ĝ
Ģ
ģ
Ğ
ğ
Ġ
ġ
Ĥ
ĥ
Ħ
ħ
Í
í
Ì
ì
Î
î
Ï
ï
Ĩ
ĩ
Ǐ
ǐ
Ī
ī
Ĭ
ĭ
İ
ı
Į
į
Ĵ
ĵ
Ķ
ķ
Ĺ
ĺ
Ļ
ļ
Ľ
ľ
Ł
ł
Ń
ń
Ñ
ñ
Ņ
ņ
Ň
ň
Ó
ó
Ò
ò
Ô
ô
Ö
ö
Õ
õ
Ǒ
ǒ
Ō
ō
Ŏ
ŏ
Ǫ
ǫ
Ő
ő
Ŕ
ŕ
Ŗ
ŗ
Ř
ř
Ś
ś
Ŝ
ŝ
Ş
ş
Š
š
Ș
ș
Ț
ț
Ť
ť
Ú
ú
Ù
ù
Û
û
Ü
ü
Ũ
ũ
Ů
ů
Ǔ
ǔ
Ū
ū
ǖ
ǘ
ǚ
ǜ
Ŭ
ŭ
Ų
ų
Ű
ű
Ŵ
ŵ
Ý
ý
Ŷ
ŷ
Ÿ
ÿ
Ȳ
ȳ
Ź
ź
Ž
ž
Ż
ż
Æ
æ
Ǣ
ǣ
Ø
ø
Œ
œ
ß
Ð
ð
Þ
þ
Ə
ə
格式
链接
标题
列表
文件
参考
讨论
说明
输入内容
输出结果
斜体
''斜体文字''
斜体文字
粗体
'''粗体文字'''
粗体文字
粗斜体
'''''粗斜体文字'''''
粗斜体文字
== query - Run 数据库上的任何查询 == 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: 将第十三篇文章添加到类别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. 将[[WordPress:Pages|网页]]15的母网页设置为网页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>
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)