Doctrine2 and UTF-8
Hey everybod out there :) I'm using CodeIgniter and Doctrine2 as my ORM. I'm having problem with storing and retrieving UTF-8 texts from my database.
I've red something about PostConnection Events but im not really sure where to add this stuff :/
My Datab开发者_如何学Goase and the tables have UTF-8 Encoding.
Can some tell me how i can fix this? :)
greetings
You have to tell your entityManager explicitly you want to use UTF-8. You don't show any code, so I just give you my snippet:
// $entityManager is an instance of EntityManager
// Add UTF8 handler to EntityManager
$entityManager->getEventManager()->addEventSubscriber(
new \Doctrine\DBAL\Event\Listeners\MysqlSessionInit('utf8', 'utf8_unicode_ci')
);
This worked for me. Also, make sure you only use multibyte functions of PHP (http://php.net/manual/en/book.mbstring.php).
精彩评论