Answer the question
In order to leave comments, you need to log in
How to search by json string in database?
Good afternoon. There is a row in the database (mysql) of the form
{"interval":["пн,вт","ср"],"tm1":["08:00","09:00"],"tm2":["20:00","21:00"],"notice":["",""],"hd":["0","0"]}
where tm1 is the opening time and tm2 is the closing time. How to search for this kind of string in yii2 via ActiveRecord? The fact is that in this line of records there can be no limit, and each time refers to its interval value ...
Answer the question
In order to leave comments, you need to log in
Yii2 does not provide built-in functions in AR for fetching data by JSON fields. First, write a SQL query that selects the data in the way you need, and only then think about how to translate it into Yii. In the case of MySQL, it is not at all clear what justifies storing a JSON array if it is necessary to search for it. It would be much better to redesign the DB
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question