MySQLiQuery_Exception'与消息'非法混合排序(latin1_swedish_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE) - 与PHP5

时间:2009-04-23 15:46:06

标签: php mysql utf-8 collation

我有这个错误:

Fatal error: Uncaught exception 'MySQLiQuery_Exception' with message 'Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=': select id from 'addresses' where 'shiptozip'='13000' and 'shiptostreet'='Františka Křížka'

正如您所看到的,我正在尝试从表地址中获取ID。

mysql> show variables like 'character%';

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+


mysql> show variables like 'collation%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_general_ci |
| collation_server     | utf8_general_ci |
+----------------------+-----------------+

表'地址'也有utf8_general_ciutf8。我想这与查询FrantiškaKřížka有关,因为它可以与其他查询一起使用。 server_collat​​ion曾经是latin_swedish_ci,但我想我现在已经设法改变了这一点(正如你从上面的表中看到的那样)。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您可以在“shiptoaddress”和“shiptozip”列中对您的问题附加排序:

SHOW FULL COLUMNS FROM addresses;

根据您提供的证据,可能发生的事情是“shiptoaddress”列仍然具有latin1编码。为表设置编码/排序规则时,您将设置默认值。可以为单个列覆盖此默认值。

如果查询适用于where address = 'Frank'但不适用于where address = 'Františka',那是因为“Františka”无法转换为latin1。