Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorjervis
    • CommentTimeSep 9th 2007
     
    how to set the connection to the database, where should I plus the 'SET NAMES utf8'?

    in the model ?
    •  
      CommentAuthorbermi
    • CommentTimeSep 9th 2007
     

    I wouldn't put it in the model.

    The best way if you have control over the server is to edit /etc/my.cnf and add

    init_connect='SET NAMES utf8'
    

    or you could implicitly call this in your app/application_controller.php

    class ApplicationController extends AkActionController
    {
        function __construct()
        {
            $this->beforeFilter('_configureMySqlCharset');
        }
        function _configureMySqlCharset()
        {
            $db =& Ak::db();
            $db->Execute('SET NAMES utf8');
        }
    }
    

    or set UTF8 in your migrations for each database table using

    function up_2()
    {
        $this->db->Execute("ALTER DATABASE table_name SET CHARACTER SET utf8;");
    }
    

    As Akelos is utf8 by default we might consider automating this in a future, but keeping in mind that it is only supported after MySQL 4.1

    • CommentAuthorjervis
    • CommentTimeSep 9th 2007
     
    thank you, bermi
    • CommentAuthortom
    • CommentTimeJan 27th 2008 edited
     

    Hi,

    init_connect='SET NAMES utf8'
    

    seems to work for me as well...

    Cheers,

    Tom

    • CommentAuthortanaka
    • CommentTimeJun 8th 2008
     

    I found a strange phenomenon about this topic.

    $_SESSION['__flash'] is always empty when

    define('AK_SESSION_HANDLER', 1);
    

    and

    class ApplicationController extends AkActionController
    {
        function __construct()
        {
            $this->beforeFilter('_configureMySqlCharset');
        }
        function _configureMySqlCharset()
        {
            $db =& Ak::db();
            $db->Execute('SET NAMES utf8');
        }
    }
    

    in application_controller.php.

    In this situation, Akelos sends queries in order below.

    1. SELECT value FROM sessions WHERE id = [value of AK_SESSID]
    2. SET NAMES utf8
    

    And, as a result, "flash()" doesn't work. $_SESSION['__flash'] is always empty.

    So, I put this code in config/boot.php and don't use "beforeFilter('_configureMySqlCharset')" in ApplicationController.

    // set names charset
    if (!defined('AK_SET_NAMES')) {
        require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
        global $dsn;
        $dao =& Ak::db(&$dsn);
        $dao->Execute('set names utf8');
        unset($dao);
        define('AK_SET_NAMES', true);
    }
    

Add your comments
    Username Password
  • Format comments as