MySQL模糊查询unicode汉字

最难相处的女生是那种很爱文艺但又没什么文化的

一般的查询:

1
2
3
4
5
6
7
8
9
10
SELECT
*
FROM
`rainlab_translate_messages`
WHERE
( ( lower( message_data ) LIKE '%"\u4ef7\u683c"%' ) )
AND `domain_id` = 1
ORDER BY
`message_data` ASC
LIMIT 500 OFFSET 0

这样的查询是查不到结果的,应该改成这样

1
2
3
4
5
6
7
8
9
10
SELECT
*
FROM
`rainlab_translate_messages`
WHERE
( ( lower( message_data ) LIKE '%"_u4ef7_u683c"%' ) )
AND `domain_id` = 1
ORDER BY
`message_data` ASC
LIMIT 500 OFFSET 0

针对PHP里的,我们直接输入汉字, 可以这样进行操作:

1
$query = $query->searchWhere(str_replace("\\","_",json_encode($search)), ['message_data']);