简体   繁体   中英

UTF8 database querying and special characters

I have a Mysql database (in utf8_general_ci) and have to query columns containing special characters. The problem is: queries containing special characters do not retrieve any results – but queries containing the regular version of those characters do.

For instance, if I want to query the word “été”:

  • SELECT … WHERE column LIKE % été % will not work.
  • SELECT … WHERE column LIKE % ete % will work!

This problem must be due to my encoding (both queries work when done directly in phpMyAdmin).

I use PDO and followed the instruction here (http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) and, when connecting to the database, do exec(“SET CHARACTER SET utf8”) AND exec(“SET collation_connection = 'utf8_general_ci'”). What bothers me is that, excepted for this search query, the website seems to work perfectly with utf8 both for the display and the database.

I thought that I could operate a transliterate_to_ascii on the strings containing special chars. I'm however afraid that this option is suboptimal, especially for non european languages. Thank you very much for your help!

Please try running SET NAMES utf8; on mysql right after the connect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM