SQLite3 LIKE query with UTF-8 encoding

巧了我就是萌 提交于 2020-01-07 04:06:18

问题


for MySQL I'm using this and works very well with UTF-8.

SELECT * FROM cat.item_list WHERE CONVERT(item_name USING utf8) LIKE (:searchString)

I've tried same query with sqlite but it doesn't work. What should I do for UTF-8 SQLite3 search query? (with LIKE)

my current sqlite3 qry (which doesn't work with UTF-8 charsets):

SELECT * FROM item_list WHERE item_name LIKE '%$safeName%'

回答1:


Try this:

$query = "SELECT * FROM item_list WHERE item_name LIKE '%" . $safeName . "%'";




回答2:


I solved like that:

    $tr_chars = array('ç','Ç','ı','İ','ğ','Ğ','ü','ö','Ş','ş','Ö','Ü'); 
    $safeName = str_replace($tr_chars, '_', $safeName);


来源:https://stackoverflow.com/questions/41602892/sqlite3-like-query-with-utf-8-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!