SQL query normalize accents, til

Asked

Viewed 538 times

0

I often have to search for names of products that have accents.. how to normalize this?

In my table I use the collation utf8_general_ci, which serves well for upper and lower case (CI).

Now, accents, are being a problem, this collation already ignores something like, is and, á de a, the problem is (ã->Till) with a,.. what to do?

1 answer

1


Try sending a query

SET NAMES utf8;

Personally I solved the same problem by adding after the mysql connection code :

mysql_set_charset("utf8");

or: mysqli_set_charset("utf8");

or the equivalent in POO : $mysqli_link->set_charset("utf8");

And sometimes you’ll have to define the main charset of php adding this code : mb_internal_encoding('UTF-8');

On the HTML client side you have to add the following header data :

<meta http-equiv="Content-type" content="text/html;charset=utf-8" />

To use the JSON AJAX results (for example, using jQuery), you must set the header by adding :

header("Content-type: application/json;charset=utf8");
json_encode(
     some_data
);

That should solve

  • Thanks for the tips, they are useful so much that I had already applied them, the problem then was not that neither the BD’s collation, and yes of how I performed the query, it was through REGEXP, soon Summer and Summer would be different indeed, there I used the comparison with equality, something like WHERE x = 'Verao' and returned Summer and Summer records, as I expected. Grateful for the reply @Renatotavares

Browser other questions tagged

You are not signed in. Login or sign up in order to post.