Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert Emoji (UTF8 4 Byte characters) into MySQL < 5.5

I have a website that connects with iPhone and Android users. They sometimes use UTF8MB4 characters (Emoji). When inserting those characters in strings in my MySQL database (formatted UTF8) the data was cropped at the first emoji.

Unfortunately, my hoster is running MySQL 5.1.66 and is not planning to update to a newer version yet. So what is the best solution for temporary use without switching the encoding?

like image 201
andreas Avatar asked Dec 05 '22 09:12

andreas


1 Answers

I have searched the web for many hours and I came to this solution which I want to share for other people:

Use BLOB instead of text/varchar in the database fields. Like this, you can continue to use the database tables as you did before and the Emojis are shown properly. As soon as the hoster updates the MySQL version, I will continue with using UTF8MB4 as encoding.

like image 87
andreas Avatar answered Dec 26 '22 00:12

andreas