上次谈了WordPress中所有的数据库操作方法,这次挑其中一个比较常用的update
说明一下:
wpdb::update( string $table, array $data, array $where, array|string $format = null, array|string $where_format = null )
参数说明:
Parameters Parameters
- $table
-
(string) (Required) Table name
- $data
-
(array) (Required) Data to update (in column => value pairs). Both $data columns and $data values should be “raw” (neither should be SQL escaped). Sending a null value will cause the column to be set to NULL – the corresponding format is ignored in this case.
- $where
-
(array) (Required) 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”. Sending a null value will create an IS NULL comparison – the corresponding format will be ignored in this case.
- $format
-
(array|string) (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’, ‘%f’, ‘%s’ (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
Default value: null
- $where_format
-
(array|string) (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’, ‘%f’, ‘%s’ (integer, float, string). If omitted, all values in $where will be treated as strings.
Default value: null
示例
其中后两个参数可以为NULL,举个例子:
第一个参数为数据表,第二个参数为要修改的内容,第三个为选择的字段。
1 |
$wpdb->update( $table , array( 'status' => '1' ), array('murl' => $tag->name, 'status' => '9') ) ; |
看看
有一事请教,我是业余玩家。 sudo vi /etc/sudoers这个命令须在root用户下执行,弹出页面为只读。 所以我执行的是sudo nano /etc/sudoers,弹出的页面就能修改
感谢分享,这个网站真不赖
看看好不好用
这篇文章实在是太赞了,做学术的那种恪尽职守和严肃认真,全篇简明扼要没有一句废话。我引用的博主的链接。 https://www.right.com.cn/forum/forum.php?mod=r
cccc学习学习下
答案
我想卡