An error occurred while retrieving Chinese characters from mysql.

Source: Internet
Author: User
A problem occurs when mysql extracts Chinese characters and creates an email client. the content of an email is html, the header is UTF-8, and the header is gb2312. In navicat, we can see that the Chinese in the content is correct, but there is a problem after reading it in the php program. then we can read it by adding set names GBK before reading the database. I can't figure it out more and more. before writing data to the database in the program, there is a set names encoding according to the Mail header. The Mail content should be utf8. Why did I read it and ask for help from GBK? I don't understand.


Reply to discussion (solution)

No set names utf8 is executed before the database is inserted, and the PHP file is also saved as UTF-8 encoding.

No set names utf8 is executed before the database is inserted, and the PHP file is also saved as UTF-8 encoding. If the correct encoding is not set before the database is inserted, will it be garbled in navicat? I rely on the code of the mail to execute the set names project before the insert. the code is utf8.
I still don't understand why the charset in the header file is different from the charset in html.

Subject: =? UTF-8? B? M + aciOenr + WIhuaciOe7k + wnscsi =? =
Content-Type: text/html;
Charset = "UTF-8"
Content-Transfer-Encoding: quoted-printable
Date: Tue, 26 Mar 2013 05:09:07 + 0100

W3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


>

If the correct encoding is not set before the database is inserted, will it be garbled in navicat?
Not necessarily, you insert gbk data, and your navicat may be gbk encoding by default. So it is normal.

It depends on what you set names.

Character set declaration is just a label.

Character set declaration is just a label.
Worship God ~

What is your page code?

Change all to UTF-8

If garbled code occurs, it is the encoding problem. let's see what went wrong.

Change to gb2312

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.