M
M
Messi2017-06-26 10:36:41
MySQL
Messi, 2017-06-26 10:36:41

How to change encoding using migrations?

Now, when writing Russian words to the database, I get ???????. How to change the database encoding to Russian text using migration?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Yakushev, 2017-06-28
@za4me

Can't say for sure, but it might help.

$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 ENGINE=InnoDB';
}

In any case, what prevents you from assigning an encoding when you create a DB?

I
Igor Vasiliev, 2017-07-23
@Isolution666

I can assume that you wrote a site in Notepad ++ or a table in Excel in windows 1251 encoding
. Because if you write projects in the IDE, the encoding is set there even before the project is created, and all subsequent files are created in the same encoding from the settings.
If I guessed right with the table, then create an empty Excel document , go to the "data" tab , "getting external data" , "from text" , select the table, set the encoding to utf-8 , separator ";" and save as csvfile, in this encoding, now you can upload it to the database and not worry, everything will be in Russian without any questions.
I can also assume that the table was created in the wrong encoding, go to PhpMyAdmin and see what kind of encoding the table itself has, and each row in the table, if the site is in UTF-8 , then the table should have utf_8_general_ci - it seems like this is written.
---
Migrations - https://yiiframework.com.ua/ru/doc/guide/2/db-migr...
Creating and deleting tables - https://metanit.com/web/php/7.3.php
Creating MySQL databases - php.net/manual/ru/function.mysql-create-db.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question