Yii and UTF8 Display, UTF8 works with mysqli, but not with the yii backend

I'm struggling to get Yii to display utf8 correctly, even if both apache servers and my database are configured to display it correctly.

In particular, I have a kanji / kana dataset that I retrieve from the mysql database. As a simple test on it, I created a browse page to retrieve data from it using mysqli and with the yii mvc architecture. When it is pulled out using mysqli, it displays correctly, but when using yii it does not. And this is from the same exact page, which also means it from the same controller. Did I miss something by forcing the model backend to use utf8 encoding?

Image: http://i.imgur.com/BLmrP.png

Here is the code that I use in the view file for the yii mvc file:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'enablePagination' => false,
)); ?>

And then mysqli is what you expect.

Any help would be greatly appreciated.

+1
source share
1 answer

You must specify the encoding for connecting to the database. This is done in your main configuration file (by default this protected/config/main.php), which looks something like this:

return array(
    ......
    'components'=>array(
        ......
        'db'=>array(
            'connectionString'=>'sqlite:protected/data/source.db',
            'charset'=>'utf8',
        ),
    ),
    ......
);

If the parameter is charsetnot specified explicitly, the connection is usually latin1, so you see gibberish.

In addition, there is a wiki entry for setting up Unicode correctly .

+2
source

All Articles