Page 1 of 1
Illegal mix of collations (utf8mb4
Posted: Mon Oct 14, 2024 4:45 pm
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";
Re: Illegal mix of collations (utf8mb4
Posted: Mon Oct 14, 2024 6:13 pm
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');