Emoji is not saved in mysql (???????) in Magento 2

Posted on

(MySQL) UTF-8 does not support all emoji. You need to change DB columns to “utf8mb4”.

Bug fix options:

1) Database: Change default character set to utf8mb4.

2) Table: Change default character set for the table as CHARACTER SET utf8mb4 COLLATE utf8mb4_bin.

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

3) Set utf8mb4 for database connection:

$database_connection = new mysqli($server, $user, $password, $database_name); 

Test sql query: 

INSERT INTO table_name (column1, column2, column3, )
VALUES ('1', 'Test 😜😊😃😀 text 我 ❌', '2022-01-14 08:08:08');

Tested in Magento 2.4.3