我的代码:
$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' ")
我的错误:
我的清单:致命错误:未捕获 mysqli_sql_exception:您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在 'json)) WHERE id = '8451'... 附近使用的正确语法
['name' => 'jak', 'age' => 13] let it be: ['name' => 'jorj', 'age' => 21]
$newElements = json_encode(['name' => 'jorge', 'age' => 23]);
// Ensure the new elements are properly escaped for use in the SQL query
$newElements = mysqli_real_escape_string($db, $newElements);
$query = "
UPDATE dl
SET data = JSON_REPLACE(data, '$.list', CAST('$newElements' AS JSON))
WHERE id = '$ID'
";
mysqli_query($db, $query) or die(mysqli_error($db));