How to solve mysql garbled characters

Source: Internet
Author: User
Mysql garbled mysql storage garbled. I want to use AJAX to POST a few pieces of data to the server. the corresponding php file receives and stores the data into mysql. the content in the insert statement parameters of mysql_query function is correct, but after saving the data to the database, all Chinese characters are garbled, and the Chinese characters read by the mysql_query function are garbled. I wrote a non-$ _ POST mysql garbled code separately.
Garbled characters are stored in mysql. I want to use AJAX to POST a few pieces of data to the server. the corresponding php file receives and stores the data into mysql. the content in the insert statement parameters of mysql_query function is correct, but after saving the data to the database, all Chinese characters are garbled, and the Chinese characters read by the mysql_query function are garbled.
I wrote a program that saves data directly in php using a Chinese string without the $ _ POST parameter. it is normal to read and write Chinese characters.

------ Solution --------------------
This is the encoding problem. we need to check what the ajax file encoding is. we need to check the encoding of the packaged mysql database, the ajax file, and the PHP file .. In short, we need to unify it. For example, all are UTF-8
Of course, transcoding iconv can also be used.
------ Solution --------------------
If you use ajax json to pass the value. Then you need to perform an encoding conversion on the server, which may be 99% required. Iconv ()
------ Solution --------------------

And
Header ("Content-Type: text/html; charset = gb2312 ")
The function is the same, so that the browser uses gb2312 encoding to read text.

Mysql_query ("set names 'gb3212'") is for databases.

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.