$q = $this->createQuery('q')
->where('q.group_id=?', $group_id)
->andWhere('q.content=?', $content)
->execute();如果我的$content包含任何unicode字符(例如中文/日文),这将导致以下消息:
SQLSTATE[HY000]: General error: 1267 Illegal mix of collations
(latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='以前有没有人遇到过类似的问题?
发布于 2012-01-11 11:40:37
可以在where子句中将COLLATE函数与MySQL一起使用,需要将入站数据转换为列排序规则(latin1_swedish_ci)
$q = $this->createQuery('q')
->where('q.group_id=?', $group_id)
->andWhere('q.content = _latin1 ? COLLATE latin1_swedish_ci', $content)
->execute();有关collate函数的详细信息,您可以查看http://dev.mysql.com/doc/refman/5.6/en/charset-collate.html,其中包含详细信息,这是从MySQL4.1开始提供的。
您还可以在表结构的定义中设置每个列的排序规则(请参见http://dev.mysql.com/doc/refman/5.6/en/charset-column.html)以了解详细信息。
希望这能有所帮助。
https://stackoverflow.com/questions/7369169
复制相似问题