Garbled characters are displayed in the database when Chinese data is inserted into the Mysql database using php.

Source: Internet
Author: User
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");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.