1

If look for a mysql entry with the value "BLUE", I can find it with the following entry: SELECT * FROM objects WHERE name LIKE '%blue%'. That's fine, and what I want.

However: If I'm looking for a mysql entry with the value "BLÅ", SELECT * FROM objects WHERE name LIKE '%blå%' returns nothing. I want it to return the row.

I'm using the php mysqli object to interact with mysql.

The column character set is utf8. Table collation is utf8_unicode_ci.

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • 1
    Have you correctly configured the [character set of your database connection](http://dev.mysql.com/doc/en/charset-connection.html)? – eggyal May 31 '16 at 10:24
  • @eggyal, here's the charset configuration. Do you see any problems with it? character_set_client | utf8 character_set_connection | utf8 character_set_database | latin1 character_set_filesystem | binary character_set_results | utf8 character_set_server | latin1 character_set_system | utf8 character_sets_dir | /usr/share/mysql/charsets/ Sorry this looks bad, I haven't figured out how to properly format in this editor... – andreas_sagen May 31 '16 at 10:37
  • The connection character set has to match the encoding in which you send that string literal `'%blå%'` to MySQL. Since PHP doesn't have any intrinsic understanding of string encodings, that's something you need to track/manage yourself. How did that string get into PHP? If it's hardcoded in the source file, it will be in the source file's encoding. If it was received into PHP from some other source (e.g. a browser), it will be in whatever encoding that source generated it. – eggyal May 31 '16 at 10:44
  • See [UTF-8 all the way through](http://stackoverflow.com/q/279170) for further information. – eggyal May 31 '16 at 10:46
  • I used set_charset() to set string encoding so that it corresponds to character_set_connection, but result is the same. – andreas_sagen May 31 '16 at 11:25
  • `set_charset()` just sets `character_set_connection` (ie how MySQL interprets the bytes that it receives). It doesn't change the encoding of the string that's in PHP, or the encoding in which it's sent to MySQL. – eggyal May 31 '16 at 11:28
  • Ah, I see. Tried mb_convert_encoding('UTF-8'), but that failed me as well. – andreas_sagen May 31 '16 at 11:42
  • Why do you keep randomly trying functions without understanding what they do?? `mb_convert_encoding` *assumes* that the string is already in the `from_encoding`, which defaults to mbstring's internal encoding if not explicitly given. You need to find out what encoding your string is in first, as previously mentioned in my comment above: ***How did that string get into PHP? If it's hardcoded in the source file, it will be in the source file's encoding. If it was received into PHP from some other source (e.g. a browser), it will be in whatever encoding that source generated it.*** – eggyal May 31 '16 at 11:47
  • Ah, I misunderstood what mb_convert_encoding does. Found the encoding, made them match, and it works now :) – andreas_sagen May 31 '16 at 12:09

0 Answers0