Doctrine2 with Symfony2 not recognizing db charset and collation

爷,独闯天下 提交于 2020-01-15 14:11:46

问题


I am trying to get Doctrine2 to work properly with a mysql db in Symfony2 on a debian squeeze system. The charset and collation of the DB are set to utf8 and utf8_general_ci and the db is created manually by reading in an sql script.

Now I enter some values for one of the tables with danish special chars like æøå and they simply wont display correctly.

My parameters.yml has set encoding: utf8 and in my config.yml the doctrine configuration has:

doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

When I do a select in the mysql console, the characters display correctly and also if I try by replacing the output array in the controller by som hardcoded values, so the problem seems definately to stem from some kind of error/bug in doctrine2 configuration...

Does anybody have any clues on how to solve this?

Thanks a lot.


回答1:


Ok I finally figured it out... there is some kind of double encoding going on with this configuration. Commenting out charset: UTF8 from doctrine dbal config solves the problem.




回答2:


the problem might be in your application charset. it can be found in config.yml

framework:
  charset:         UTF-8
  #translator:      { fallback: lt }
  #secret:          %secret%
  #other options


来源:https://stackoverflow.com/questions/16260814/doctrine2-with-symfony2-not-recognizing-db-charset-and-collation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!