Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpMyAdmin mysql saved Emoji as Question mark

I want to save Emoji into MySql database, and I realize, three bytes Emoji is saved correctly in the database, but 4 byte emoji have been saved as question marks. It seems like I did fully convert utf8 to utf8mb4, but I dont know what exactly is missing here. My MySQL version is 5.5.29, when I do a SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; in MySql shell, it shows the following:

+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | utf8mb4            |
| character_set_connection | utf8mb4            |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | utf8mb4            |
| character_set_server     | utf8mb4            |
| character_set_system     | utf8               |
| collation_connection     | utf8mb4_unicode_ci |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | utf8mb4_unicode_ci |
+--------------------------+--------------------+

Now, for testing purpose, I only have 1 database with 1 table created to test emoji saving. I created the database through phpMyAdmin, and created the table through MySql shell:

CREATE TABLE `test_emojis` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

and it still does not work (still question marks).

However, I found something interesting, I see question marks in phpMyAdmin, but I can see emoji icon properly in Mysql shell if I type select * from test_emoji; any ideas?

Can someone help please?

Thanks

like image 432
user2002692 Avatar asked Jan 23 '13 05:01

user2002692


People also ask

Why are my emojis showing up as a question mark?

The issue happens because your device doesn't support the same emojis as the sender's device. It could because your operating systems have different Unicode support. For example, if you send emojis from the newest iPhone to an older Android device, the chances are that the recipient will get a row of question marks.

How do I save emojis in phpmyadmin?

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.

Can MySQL store emoji?

To store emoji in an RDS for MySQL DB instance, ensure that: The client outputs the utf8mb4 character set. The connection supports the utf8mb4 character set. If you want to use a JDBC connection, download MySQL Connector/J 5.1.

How do I save emojis to my database?

There are two ways to save images. Most common way is to save the file name in MySQL table and upload image in folder. Another way is to store the image into directly into the Database. As, Developers usually don't use the second method, they might get confused.


2 Answers

phpMyAdmin has hardcoded utf8 charset so you would have to edit it's code to change this. For future versions it's fixed in fb30c14 (this shows you also where to change these values).

like image 123
Michal Čihař Avatar answered Nov 01 '22 15:11

Michal Čihař


Upgrade your phpMyAdmin to >= 4.3.9 and problem solved.

like image 3
James Gwee Avatar answered Nov 01 '22 16:11

James Gwee