Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation 'find_in_set'

为君一笑 提交于 2021-02-05 11:13:22

问题


I get the following error:

Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (utf8_general_ci,IMPLICIT) for operation 'find_in_set'

This is the query I was trying to execute:

SELECT ID FROM xs_user_profiles WHERE ID='' AND FIND_IN_SET('1',site_structure);

I looked up the properties of this table and it has charset utf8 and collation utf8_general_ci.

This works well with all my sites so I am not sure what's going wrong.


回答1:


If you are using mysqli, issue this command right after connecting:

$mysqli->set_charset("utf8");

This will set your connection encoding to UTF8 (same as your table uses).

With plain mysql, use this:

mysql_query("SET NAMES utf8", $conn);
mysql_query("SET CHARACTER SET utf8", $conn);



回答2:


I'm guessing your string literal ('1') is in a different collation due to different connection variables. See here



来源:https://stackoverflow.com/questions/940107/illegal-mix-of-collations-latin1-swedish-ci-coercible-and-utf8-general-ci-imp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!