douba9425 2011-03-23 15:04 采纳率: 100%
浏览 46
已采纳

Doctrine2和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 Database and the tables have UTF-8 Encoding.

Can some tell me how i can fix this? :)

greetings

  • 写回答

1条回答 默认 最新

  • dongwo5449 2011-08-24 12:13
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题