0

In my database user stores data in Japanese characters. When I query those data I did not get the data in Japanese characters but I got 入力ãªã— in stead. I don't know how to solve this. Below is my database configuration.

Yii::$app->components = [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;dbname=my_database',
        'username' => '****',
        'password' => '****',
        'charset' => 'utf8',
    ],
];

If I remove 'charset' => 'utf8', I got ??????? in stead of strange characters above or Japanese characters. I work with Yii framework 2 and with its ActiveRecord. Anyone knows any solutions?

O Connor
  • 4,236
  • 15
  • 50
  • 91

1 Answers1

0

I'm willing to bet that your database or your tables have the wrong charset/Collation. Check databases:

SELECT * FROM information_schema.SCHEMATA

Check tables:

SHOW FULL COLUMNS FROM table_name;

It's possible to convert existing data (from latin1 to utf8 for example) but not super-easy. I would say you'll have an much easier time just changing the default charset "How to make MySQL handle UTF-8 properly" and create new database/tables rather than convert existing data.

Community
  • 1
  • 1
ippi
  • 9,857
  • 2
  • 39
  • 50