There is a parser on yii2 (php). It parses text from various sites and inserts it into the database. When I try to save to the database, I get this error message.

Error: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF1\xE0\xEB\xEE\xED\xFB...' for column 'about' at row 1 

Mysql version 5.7 Encoding

 -------------- show variables like '%colla%' -------------- +----------------------+-----------------+ | Variable_name | Value | +----------------------+-----------------+ | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | +----------------------+-----------------+ 3 rows in set (0.00 sec) mysql> show variables like '%charac%'; -------------- show variables like '%charac%' -------------- +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec) 

Config connection to the database

 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yiiutf8', 'username' => 'root', 'password' => 'xxxx', 'charset' => 'utf8', ], 

I tried to change the encoding to

  • utf8mb4
  • utf8_general_ci
  • utf8_unicode_ci
  • utf8mb4_general_ci
  • utf8mb4_unicode_ci
  • You have a string in cp1251 (salons are written there), and you try to decode it as a utf-8 string. And for a Cyrillic text is impossible. Most likely you need to process the line with something like this `$ messageutf8 = iconv ('windows-1251', 'UTF-8', $ message1251);` - KoVadim
  • General error: 1366 Incorrect string value: '\ xF0 \ x9F \ x91 \ x8D \ x0A \ xD0 ...' for column 'about' at row 1 .... It helped in the first case, but did not insert Utf8 - Olala Xd

0