Answer the question
In order to leave comments, you need to log in
How to properly store Cyrillic json in MySQL?
This is the first time I've encountered this problem!
I create a JSON string with Cyrillic.
json_encode($data);
Instead of Cyrillic \uXXX\uXXX
I stuff it into MySQL and the icons disappear \ remains uXXXuXXX
I do not use any screening functions. What and how to do it right?
This is how I decided to save the database in UTF8, the files in UTF8, the connection in the same encoding.
json_encode($massx,JSON_UNESCAPED_UNICODE);
How wrong/dangerous is this?
Thanks in advance to all who answer!
Answer the question
In order to leave comments, you need to log in
Your slashes disappear at the php level, this can apparently be checked by running str_replace('\\u','\\\\u',json_encode($data));
Glitches at the Mysql level can be roared by converting the type of the field into which json is written to the blob type, if it is ok, then something is wrong with the encodings in the database or connecting to it.
json_encode($massx,JSON_UNESCAPED_UNICODE); will not solve the problem with slashes, they are used not only for unicode
Added:
slashes in lines are used to write non-printing/control codes as letters. It's not mysql, it's like that everywhere . For example \t is not a slash + t (two characters), it is one tab character. likewise, \u is not two characters, but one, damn it.
if you do insert into t set col = 'a\n\n\nb'; and then select col from t; then you take:
a
b
i.e. three empty lines between a and b, if you want to keep the combination \n itself, then you need to write insert into t set col = 'a\\n\\n\\nb'; Then the select will be a\n\n\nb, because in order to encode a slash in a string, it must be escaped with the same slash. This is fine.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question