kymbrik
1/21/2019 - 1:55 PM

Как сохранить эмодзи в mysql utf8mb4

  1. Добавляем строку в конфиг mysql (/etc/mysql/percona-server.conf.d)
  character_set_server=utf8mb4

sudo service service mysql restart

  1. Database: Change Database default collation as utf8mb4
  2. Table: Change table collation as CHARACTER SET utf8mb4 COLLATE utf8mb4_bin.
ALTER TABLE Tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin
  1. Code:
INSERT INTO tablename (column1, column2, column3, column4, column5, column6, column7)
VALUES ('273', '3', 'Hdhdhdh😜😀😊😃hzhzhzzhjzj 我爱你 ❌', 49, 1, '2016-09-13 08:02:29', '2016-09-13 08:02:29')
  1. Set utf8mb4 in database connection:
  $database_connection = new mysqli($server, $user, $password, $database_name); 
  $database_connection->set_charset('utf8mb4');