Illegal mix of collations (utf8mb4

Post Reply
mister_v
Posts: 199
Joined: Thu Mar 04, 2010 9:19 pm

Illegal mix of collations (utf8mb4

Post by mister_v »

Hello,

My query fails, error message:

Code: Select all

Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb3_general_ci,COERCIBLE) for operation '='
$sql="SELECT media,datum,title FROM messages WHERE id='".$obj->get_id() ."' AND media='".$obj->get_media()."' AND title='".$obj->get_title()."' LIMIT 1";
chris
Site Admin
Posts: 205
Joined: Mon Jul 21, 2008 9:52 am

Re: Illegal mix of collations (utf8mb4

Post by chris »

The problem is comparing different encode character-sets.

You can see the character-sets with:

Code: Select all

SHOW VARIABLES LIKE 'char%';
SHOW CREATE TABLE table_name;
FYI: utf8mb4 is NOT a character encoding, utf8mb4 is just MySQL's nickname for utf8. what MySQL calls utf8 is actually a 3-byte subset of the real utf8. and what MySQL calls utf8mb4 is the real utf8.

if you use php, you can use mb_convert_encoding() to convert

Code: Select all

mb_convert_encoding($text, "UTF-8");
Should work in most cases, but I hear it sometimes has problems detecting the original character set correctly.

If you know the original character set, use mb_convert_encoding()
example :

Code: Select all

mb_convert_encoding($string, 'UTF-8', 'Windows-1252');
Post Reply