my code:
$newElements=json_encode(['name'=>'jorge','age'=>23]);
mysqli_query($db, "UPDATE dl SET data=json_replace(data, '$.list', cast('$newElements' as json)) WHERE id = '$ID' ")
my Error:
Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘json)) WHERE id = ‘8451’…
That my list of:
['name' => 'jak', 'age' => 13] let it be: ['name' => 'jorj', 'age' => 21]
2
Answers
Check our path (JSON path) and also try to pass the elements with full path like the code below:
Suppose we have users table and chamber col (JSON col), containing this ({"age": 33,"name": "Khaled"}) after the above query you will get the updated values ({"age": 31,"name": "Ahmed"}) and don’t forget the where clause ;).