1. I have written a php code to insert a field value with Chinese characters to the mysql database. in phpMyadmin, garbled characters are displayed. in mysql console, garbled characters are displayed. I have changed the sorting rules for each field to uft8_general_ci, it is normal to directly insert in phpmyadmin. in mysql control...
1. I have written a php code to insert a field value with Chinese characters to the mysql database. in phpMyadmin, garbled characters are displayed. in mysql console, garbled characters are displayed. I have changed the sorting rules for each field to uft8_general_ci, direct insertion in phpmyadmin is normal, and direct insertion in mysql console is also normal, but it is not normal to insert through php. I also wrote header ("Content-Type: text/html; charset = utf-8 ");
3. could you please help me find out what the problem is?
Reply content:
1. I have written a php code to insert a field value with Chinese characters to the mysql database. in phpMyadmin, garbled characters are displayed. in mysql console, garbled characters are displayed. I have changed the sorting rules for each field to uft8_general_ci, direct insertion in phpmyadmin is normal, and direct insertion in mysql console is also normal, but it is not normal to insert through php. I also wrote header ("Content-Type: text/html; charset = utf-8 ");
3. could you please help me find out what the problem is?
If your database table contains normal Chinese characters, try to insert data. Unified character encoding format:
Make sure that the database, table, and field are all set.utf-8
Make sure that the character set isutf-8
Make sure that the program file isutf-8
Make sure that the character set in the configuration file of the mysql installation programutf-8
I have found the key to the problem. I have tried both of the following two answers, which is ineffective. the problem lies in mysql. default-character-set = utf8 is missing in ini configuration. I installed wampserver and used this software to install mysql. ini does not have that sentence, and if you add this sentence, the position must be added to the position indicated by my image.
Use show variables like 'character _ set _ %; to view the character encoding after the INI file is modified, as shown in
You need to set mysql encoding to execute SQL "set names utf8"
Set character set
mysqli_set_charset($con, "utf8");