メモ:Doctrine2でMySQL利用時のcreate table文を発行しているところ

charsetとかに対応していないっぽい。

DB接続時(MySQL)に「set names utf8」を投げるには、Doctrine-DBALにあるMysqlSessionInitを有効にする。(なぜデフォルトでは使われていないのかよく分からない)

例えば、HelloBundleのbootメソッドに、以下のように記述する。

<?php
namespace Application\HelloBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;

class HelloBundle extends Bundle
{
    public function boot()
    {
        $em = $this->container->get('doctrine.orm.entity_manager');
        $em->getEventManager()->addEventSubscriber(new MysqlSessionInit('utf8', 'utf8_unicode_ci'));
    }
}