Answer the question
In order to leave comments, you need to log in
How to save emoji utf8mb4 in mysql on shared hosting?
Good day everyone, such a question - there is shared hosting on reg.ru, I'm trying to save emoji emoji in utf8mb4 encoding to the mysql database (they are not written in utf8 at all), but it is saved in the database and when reading from the database, instead of each emoji character, it displays ?? ??. The connection to the database itself occurs through a script
$link = mysql_connect('localhost', 'u0088888_default', 'pass');
mysql_select_db('u0088888_default', $link);
mysql_query("SET NAMES 'utf8mb4'");
mysql_query("SET CHARACTER SET 'utf8mb4'");
mysql_query("SET SESSION collation_connection = 'utf8mb4_unicode_ci'");
Answer the question
In order to leave comments, you need to log in
To store characters with codes greater than 0xFFFF, it is not enough to set the session encoding, it is necessary that the database tables have the utf8mb4 encoding. Recreate the database tables with explicit utf8mb4 encoding.
But keep in mind that the maximum length of the index value in BYTES does not change. Therefore, if you have indexes on fields of the VARCHAR type, then for utf8mb4 (4 bytes per character instead of 3 for utf8), the length of these fields should not exceed 191 characters (255*3/4).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question