Querying JSON data in MySQL
There is a field in 1.mysql that stores data in JSON format.
2. Now you need to pass the parameters from the page to PHP and search for the matching keywords.
3. After json_encode the keyword page, go to like to match this field, not match
Solution:
1. Only for Chinese search, the same data is stored in json,josn the Chinese is generally Unicode-encoded, and the keywords are encoded.
2. In MySQL, "\" needs to be escaped. Two solutions:
A) so use "\ \" To query, the data is still empty. (after the MySQL stick escapes, it escapes other characters, all of which need to be escaped by adding a diagonal bar.) ) to the last four diagonal bars "\\\\", so as to get a "\".
b) Then you can find it by replacing it with _ (underscore) and then retrieving it.
PHP Demo:
$payer =trim (@$_post[' payer ');
if (!empty ($payer)) {
$json _payer=str_replace ("\ \", "_", Json_encode ($payer));
$where. = "and extend_params like '%". $json _payer. " %‘ ";
}
This article is from the "Yanzi" blog, make sure to keep this source http://daddysgirl.blog.51cto.com/1598612/1761718
MySQL Fuzzy query table JSON-formatted data-177