Storing emojis in MySql database. Showing ??? in phpmyadmin

11,658

Solution 1

I finally got the solution. We will have to set our connection charset to utf8. After declaring connection variable set charset:

mysqli_set_charset($con,"utf8");

After that your emoji or any other unicode text will be encrypted and saved in mysql database.

Solution 2

See this answer: you need to have utf8mb4 set everywhere on the way when saving and loading, PHP must know to use the encoding as well when communicating with database.

After you added screenshot: there most probably already is bad data in your database - I would guess the problem is in the way you save the emoji to the database, not in the way you load it (could be both though).

Share:
11,658
Siddhant Dixit
Author by

Siddhant Dixit

Updated on June 05, 2022

Comments

  • Siddhant Dixit
    Siddhant Dixit almost 2 years

    Showing question mark ??? while storing emoji in a MySQL database. I have already set database and table collation to utf8mb4. But still, it's showing ??? ??? instead of emoji in the database. I also tried to change existing row in PHPMYADMIN console. But nothing is working. Showing ??? instead of Unicode characters. I have also changed Storage Engine for the table. InnoDB, MyISAM

    SET NAMES utf8mb4;
    
    ALTER DATABASE your_database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
    
    ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
    

    table structure and all elements