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

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

报告相同问题?

悬赏问题

  • ¥30 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动