Configure MySQL with full utf8 support

When I start with MySQL and Zend Framework, I wonder why I get different characters when using German ‘öäüß’. Sure this happen with all special characters. Trying around I found the solution. May I create the database in utf8 and also my Zend View and my layout is encoded in utf8, but the mysql connection is in latin1.

To test your settings, just connect to your mysql database and use this query show variables like 'character_set_%';
The output will look like this:

+--------------------------+-----------------------------------------------+
| Variable_name            | Value                                         |
+--------------------------+-----------------------------------------------+
| character_set_client     | utf8                                          |
| character_set_connection | utf8                                          |
| character_set_database   | utf8                                          |
| character_set_filesystem | binary                                        |
| character_set_results    | utf8                                          |
| character_set_server     | utf8                                          |
| character_set_system     | utf8                                          |
| character_sets_dir       | /usr/local/mysql-5.0.67/share/mysql/charsets/ |
+--------------------------+-----------------------------------------------+

If your settings are not in utf8 but latin1 for example, you can change them using the “set” command.
Like here set character_set_client = utf8;

These changes are only for the current session. So you have to fire them in the bootstrap file of Zend Framework, or you simply change the my.cnf configuration file.

Doing so, your configuration file will have these entries:

[client]
default-character-set   = utf8

[mysqld]
collation_server         = utf8_unicode_ci
default-character-set    = utf8

[mysql]
default-character-set   = utf8

Zend Framework

Don’t forget to add follow entry to your application.ini
resources.db.params.charset = "utf8"
to set the connection to utf8.

Keine Kommentare

Beitrag kommentieren