Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persisting utf-8 data with Doctrine2 in Symfony2

I'm trying to persist some data that I get from a form in a MySQL database using Doctrine2 and Symfony 2. My problem is that this data is in Greek and although the Collation of the database and the fields is utf8_general_ci it Doctrine2 doesn't store correctly this characters.

I've checked that this characters are correct in my mapping class, so I guess that the problem is my Doctrine configuration. Any ideas of what it might be?

like image 533
lgomezma Avatar asked Nov 01 '11 16:11

lgomezma


2 Answers

I figure it out myself. I had to set Doctrine Dbal to utf8. For that I only needed to add the following to my config.yml:

doctrine:
    dbal:
      //rest of the configuration 
      charset:  utf8
like image 96
lgomezma Avatar answered Oct 13 '22 10:10

lgomezma


You also need the following entry in my.cnf:

collation-server = utf8_general_ci 
character-set-server = utf8
like image 41
codecowboy Avatar answered Oct 13 '22 10:10

codecowboy