嘿每个人都在那里:) 我正在使用CodeIgniter和Doctrine2作为我的ORM。 我在存储和检索数据库中的UTF-8文本时遇到问题。
我对PostConnection Events有些不满,但我不确定在哪里添加这些东西:/
我的数据库和表格有UTF-8编码。
有人可以告诉我如何解决这个问题吗? :)
问候
答案 0 :(得分:5)
您必须明确告诉您的entityManager您要使用UTF-8。你没有显示任何代码,所以我只给你我的代码:
// $entityManager is an instance of EntityManager
// Add UTF8 handler to EntityManager
$entityManager->getEventManager()->addEventSubscriber(
new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_unicode_ci')
);
这对我有用。另外,请确保您只使用PHP的多字节函数(http://php.net/manual/en/book.mbstring.php)。