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

前端 未结 9 1410
失恋的感觉
失恋的感觉 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 14:57

    I had the same problem while using the Doctrine2 module in my Zend Framework 2 application. Explicitly setting the character set for my Doctrine2 module solved the issue...

    Just add 'charset' => 'utf8' to your doctrine connection parameters:

    'params' => array(
        'host'     => 'localhost',
        'port'     => 'yourport',
        'user'     => 'username',
        'password' => 'password',
        'dbname'   => 'yourdatabase',
        'charset'  => 'utf8',
    )
    

    Might also work for your normal database connection. Add 'charset=utf8' to the connection string:

    'db' => array(
        'driver'         => 'Pdo',
        'dsn'            => 'mysql:host=$localhost;dbname=$yourdatabase;charset=utf8',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        )
    ),
    

提交回复
热议问题