mysql+php garbled principle and solution

Source: Internet
Author: User
Tags character set mysql code mysql create mysql version mysql database

Mysql+php generated garbled reason:

MySQL database default encoding is UTF8, if this code and your PHP page is inconsistent, may cause MySQL garbled;

MySQL creates a table when you choose an encoding, if this encoding and your Web page encoding is inconsistent, may also cause MySQL garbled;

MySQL Create a table when you add a field can choose to encode, if this encoding and your Web page encoding inconsistent, may also cause MySQL garbled;

The user submits the page the code and displays the data the page code to be inconsistent, will certainly cause the PHP page garbled;

such as the user input data page is BIG5 code, display user Input page is gb2312, this 100% will cause PHP page garbled;

The PHP page character set is incorrect;

The PHP connection to the MySQL database statement specifies an incorrect encoding.

Attention:

Many people suspect that MySQL version inconsistency will lead to garbled, I believe that read this note you would not think so.

You may have several encodings of text you see on some sites, if you see a traditional characters, it may be BIG5 encoding, it may be utf-8 encoded, more likely to be GB code, yes, that is, there are simplified traditional Chinese characters, there is also a simplified Chinese code, we must understand this.

If you are doing a simplified code of the Web page, coding for GB2312, if the Hong Kong and Taiwan region of the visitors to submit traditional information, it may cause garbled, the solution:

Set the site code to Utf-8 so that all the characters in the world are compatible.

If the site has been operating for a long time, there are many old data, can not change the setting of Simplified Chinese, then it is recommended that the encoding of the page set to GBK, GBK and GB2312 is the difference between: GBK can display more characters than GB2312, to show the traditional character of simplified code, can only use GBK

Use mysql+php produce garbled reason all know very clearly, then solve is not difficult.

mysql+php to produce garbled solution:

If the installation of MySQL code can not be changed, many friends are buying a virtual host to build a Web site, do not have the right to change the installation of MySQL code, this can be skipped, because as long as the next step together correctly, the same can solve the garbled problem.

Modify the database encoding, if the database encoding is incorrect, you can execute the following command at phpMyAdmin:

ALTER DATABASE 'test' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin

The above command is to set the test database encoding to UTF8.

Related Article

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.