如何使用doctrine2将表排序设置为utf_general_ci


How to set the table collation to utf_general_ci using doctrine2

今天我在一个使用doctrine2

的应用程序中得到了以下错误
Message: SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_unicode_ci,COERCIBLE) for operation 'like' 

我检查了phpmyadmin表的排序是latin1_swedish_ci。

在我的应用程序中,我配置doctrine使用utf8

$em->getEventManager()->addEventSubscriber(new 'Doctrine'DBAL'Event'Listeners'MysqlSessionInit('utf8', 'utf8_unicode_ci')); 

我的数据库是通过安装脚本生成的,使用了一个相同配置的实体管理器。

如何使用doctrine2设置我的表的排序为utf8_general_ci ?

之前我报告了Symfony中的一个Bug,后来转移到Doctrine。@elliot提到了创建数据库的问题。

所以在这种情况下,我猜错误仍然存在。如果您希望使用utf-8手动创建数据库,那么它将完成其他工作。

但是根据Benjamin Eberlei,他提到MySQL的postConnect事件监听器调用'SET NAMES UTF-8'。他提到的DBAL链接坏了,否则我早就去查了。

希望能有所帮助

如果使用注释,请使用下面的代码设置排序、引擎和字符集:

/**
* @ORM'Table(name="temporary", options={"collate"="utf16_latin_ci", "charset"="utf16", "engine"="MyISAM"})  
* @ORM'Entity
*/    

对于yml文件也是一样