E
E
Edward2016-02-07 10:35:27
MySQL
Edward, 2016-02-07 10:35:27

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'");

I recoded the database according to the instructions https://goo.gl/Cfkj2h , except for editing my.cnf (I don't have access to it),
the query SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; gives out
33014ec5d2c54214a300e4de2ae323af.png, although according to the instructions it should
63840f2604e44764aab615d3bb646071.png
now issue the question itself - how to solve the problem of saving emoji to the database without editing my.cnf?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Ezhgurov, 2016-02-11
@edikl

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 question

Ask a Question

731 491 924 answers to any question