PHP+MYSQL字段info為JSON類型,現在想更新ID為2里的第二個age的值,從42修改為14,前面的age等保持不變怎么搞?
2 回答

莫回無
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);

慕容森
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 關注
- 552 瀏覽
添加回答
舉報
0/150
提交
取消