MySQL查询utf-8字符(例如中文)(另外,我使用的是Doctrine)
$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 '='
以前有人遇到过类似的问题吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 where 子句中使用 MySQL 的 COLLATE 函数,需要将入站数据转换为列排序规则 (latin1_swedish_ci)
有关 collate 函数的详细信息,您可以查看 http://dev.mysql.com/doc/refman/5.6/en/charset-collate.html 其中有详细信息,这从 4.1 开始就存在于 mysql 中。
您还可以在表结构的定义中设置每列的排序规则(请参阅http://dev.mysql.com/doc/refman/5.6/en/charset-column.html)了解详细信息。
希望这有帮助。
You can use the COLLATE function with MySQL in the where clause, will need to convert the inbound data to the column collation (latin1_swedish_ci)
For details about the collate function you can have a look at http://dev.mysql.com/doc/refman/5.6/en/charset-collate.html which has the details, this have been in mysql from 4.1.
You can also set the collation per column as well in the definition of the table structure (see http://dev.mysql.com/doc/refman/5.6/en/charset-column.html) for details.
Hope this helps.