How to set charset to UTF-8 in a Zend application?

前端 未结 9 1414
失恋的感觉
失恋的感觉 2021-01-05 14:29

I am developping a Zend application. The data in my database is encoded in \"utf8_unicode_ci\". I declared in my application.ini :

resources.view.encoding =          


        
9条回答
  •  逝去的感伤
    2021-01-05 15:01

    as others said we have to set the encoding, in my Zend framework I had to do it in little different way:

    1. in db.ini file:

    charset = "utf8"

    adapter = PDO_MYSQL
    dbname = skydevel_skydevfinal
    username = root
    password = 
    hostname = localhost
    sprofiler = false
    charset = "utf8"
    

    add this line below where you declared the database, username, etc.

    2.Now in bootstrap.php file point the reference to that new line:

    'charset'=>$dbConfig->charset

    end_Db::factory($dbConfig->adapter, array('host' => $dbConfig->host,
                    'username' => $dbConfig->username,
                    'password' => $dbConfig->password,
                    'dbname' => $dbConfig->dbname,
                    'charset'=>$dbConfig->charset
    
    1. you have to set your database and table to UTF-8, here is how I have done: ALTER DATABASE skydevel_skydevfinal CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE ch_news_comments CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

提交回复
热议问题