Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set utf8 charset for doctrine issue

I am using this config for my doctrine:

$config = array(
        'name'          =>  'backend',
        'host'          =>  'xxxxx',
        'user'          =>  'xxxx',
        'password'      =>  'xxxxx',        
        'dbname'        =>  'xxxx', 
        'driver'        =>  'pdo_mysql',
        'charset'       =>  'UTF8',

    );

But my database's using utf8_general_ci. In result, when i get data from database, some characters can't show correctly as i want. I tried adding:

'driveroptions'=>array(1002=>"SET NAMES utf8")

But it doesn't work. Could someone help me.

like image 859
Haruji Burke Avatar asked Feb 05 '23 09:02

Haruji Burke


1 Answers

The character set and collation are 2 different things. I think you have 2 options.

1) Set the character set in MySQL config (the my.cnf file), by adding these lines in the [mysqld] block.

e.g.

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci

2) Try setting the collation in Doctrine config via 'options' setting.

e.g.

charset: UTF8
options:
    1002: "SET NAMES 'UTF8' COLLATE 'utf8_unicode_ci'"
like image 195
Scott Anderson Avatar answered Feb 08 '23 03:02

Scott Anderson