0

I have a mysql table with a json datatype used to store json_encoded data:

id|author_id|date_inserted|comments
---------------------------------------------
1|32|2022-04-01|{"id": "343","some":"data"}
2|15|2022-02-15|{"id": "24","some":"data"}
3|24|2022-05-22|{"id": "995","some":"data"}

Using laminas-db, how is it possible to use JSON_EXTRACT in a where clause? For instance, when using a tablegateway, i would like to update the json data of a row using something like the following:

$this->tableGateway->update($data, [JSON_EXTRACT('comments', '$.id') = 24]);

1 Answer 1

0

I was able to achieve it with the following:

 $commentId = 24;
 $where = new Where();
 $where->addPredicate(new Expression('JSON_EXTRACT(comments, "$.id") = ?', $commentId));
 return $this->tableGateway->update($data, $where);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.