MySQL Fuzzy query table JSON-formatted data-177

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.