As a web development company in Hong Kong, we are in a lot of projects with multilingual support, usually English, Traditional Chinese & Simplified Chinese. Having the web application and database running in UTF-8 is very important.
CakePHP is set to run in UTF-8 by default. However, this is not the case with MySQL. If you do your MySQL connection with purely PHP, you need to run a SQL statement.
This tells your PHP page to connect MySQL in UTF-8 collation. In CakePHP, the default database setting in database.php is like this:
var $default = array(
'driver' => 'mysqli',
'persistent' => false,
'host' => 'localhost',
'login' => {database_username},
'password' => {database_password},
'database' => {database_name},
'prefix' => ''
);
This won’t connect MySQL in UTF-8. To add UTF-8 support with MySQL in CakePHP, simply add one line after ‘prefix’ => ”.
var $default = array(
'driver' => 'mysqli',
'persistent' => false,
'host' => 'localhost',
'login' => {database_username},
'password' => {database_password},
'database' => {database_name},
'prefix' => '',
'encoding' => 'utf8'
);
Data save to and read from MySQL will be in UTF-8.