Z
Z
Zhainar2016-07-25 19:24:23
MySQL
Zhainar, 2016-07-25 19:24:23

Yii2 How to save Cyrillic in the database?

Created CRUD using a generator, when saving data in Russian, an error occurs
Incorrect string value: '\xD0\xA3\xD0\xB2\xD0\xB5...'. Who faced it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zhainar, 2016-07-25
@zhainar

Already found) Add to the migration:

$tableOptions = null;
if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
     $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci';
}
$this->createTable(
    'tablename', 
    [
      'id' => $this->primaryKey(),
      //
    ], 
    $tableOptions
  );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question