马春杰杰博客
致力于深度学习经验分享!

[WP]WordPress中的$wpdb->update使用方法

最新目录

上次谈了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,举个例子:

第一个参数为数据表,第二个参数为要修改的内容,第三个为选择的字段。

 

赞(344) 打赏
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《[WP]WordPress中的$wpdb->update使用方法》
文章链接:https://www.machunjie.com/web/webjiaocheng/568.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

:smile: :sad: :arrow: :cool: :confused: :cry: :eek: :evil: :exclaim: :idea: :lol: :mad: :mrgreen: :neutral: :question: :razz: :redface: :rolleyes: :surprised: :wink: :biggrin: :twisted: