Question :
I have in my database words with accents and when I want to call I use this SQL below.
But if a word in the database has an accent I also need to use the word accented in my search, otherwise it returns nothing.
How do I get around this situation and search for both accented and non-accented words?
SELECT * FROM produtos WHERE status_pr='online' AND (LCASE(nome_pr) LIKE '%$get%'
OR LCASE(descricao_pr) LIKE '%$get%' OR LCASE(marca_pr) LIKE '%$get%'
OR LCASE(linha_pr) LIKE '%$get%' OR LCASE(categoria_pr) LIKE '%$get%')
In the above code, $ get is the PHP variable with what will be searched.
Answer :
Copying Based on this OS response , you just have to select the fields using utf8 as charset:
SELECT * FROM produtos WHERE status_pr='online' AND (LCASE(nome_pr) LIKE _utf8'%$get%'
OR LCASE(descricao_pr) LIKE _utf8'%$get%' OR LCASE(marca_pr) LIKE _utf8'%$get%'
OR LCASE(linha_pr) LIKE _utf8'%$get%' OR LCASE(categoria_pr) LIKE _utf8'%$get%')
Try to do this:
SELECT *
FROM 'produtos'
WHERE status_pr='online' AND nome_pr LIKE _utf8 'SAO PAULO' COLLATE utf8_unicode_ci
More information – > link
Based on this question I found an answer that talks about the% SELECT CONVERT(column_name USING utf8) FROM table_name LIKE '%giga%'
that solved my problem, this may help others. Thanks Thomas