Using UTF-8 as encoding for the database connection

I already wrote about this topic some time ago. In that post I described an approach using the configuration file of MySQL, and mentioned casually that you could execute “SET NAMES utf8” if you do not have access to the MySQL configuration file. But I did not show a solution for that case…

Well, today I saw a solution, presented by nate in a post in the google group:

// app/app_model.php
class AppModel extends Model 
{ 
    function __construct() 
    { 
        parent::__construct(); 
        $this->execute("Set NAMES 'UTF8'"); 
    }
}

2 Comments

  1. Posted June 23, 2006 at 4:39 pm | Permalink

    Useful to know :). What’s the best way to execute this statement only once per connect I wonder… ?

  2. Posted June 24, 2006 at 9:07 am | Permalink

    Well, at the moment I do not know a way for doing it without hacking the core. But it will possible to set the encoding in the next version of Cake: https://trac.cakephp.org/changeset/3111.


Post a Comment

Required fields are marked *
*
*

%d bloggers like this: