PHP+MYSQL字段info为JSON类型,现在想更新ID为2里的第二个age的值,从42修改为14,前面的age等保持不变怎么搞?
2 回答
![?](http://img1.sycdn.imooc.com/5458662500019a7c02200220-100-100.jpg)
莫回无
TA贡献1865条经验 获得超7个赞
$info = '[{"age":"12", "time":"2016-04-20"}, {"age":"42", "time":"2001-09-02"}]'; $info = json_decode($info, true); $info[1]['age'] = 14; $info = json_encode($info);
![?](http://img1.sycdn.imooc.com/545865620001c45402760276-100-100.jpg)
慕容森
TA贡献1853条经验 获得超18个赞
update 表名 set info = json_set(info,"$.age","14") where id = 2; #对id为2的info键值进行修改
以下代码
update **表名** set info = json_set(info,"$.age","14") where id = 2;
- 2 回答
- 0 关注
- 527 浏览
添加回答
举报
0/150
提交
取消