I am saving the data in my database like {"name":"User Name","age":"32","gender":"M"}
I have concern when I am updating this data I want to add some more data with this JSON like "city":"City_Name","state":"State_Name"
.
so after update the final data will be like this {"name":"User Name","age":"32","gender":"M","city":"City_Name","state":"State_Name"}
-----------------------------------------------------------------------
| ID | col_name
-----------------------------------------------------------------------
| 1 | {"name":"User Name","age":"32","gender":"M"}
I can able to update existing data in JSON but don’t know How I add new data in JSON with an update query in phpMyAdmin.
Please help How me achieve the goal.
for updating, I am using the code below.
...
let obj = JSON.parse(stmt[0].col_name);
const stmt2 = await con.query("UPDATE `table` SET `col_name` = :data WHERE `col_id` = 1,
{
replacements: { data: JSON.stringify(obj) },
type: con.QueryTypes.UPDATE
});