Common PHP and Mysql Chinese garbled problem solving method _mysql

Source: Internet
Author: User

garbled problem 1: Use phpmyadmin operation MySQL database Chinese character display is normal, but when using PHP Web page to display MySQL data, all Chinese characters have become a number.

Symptom: Input Chinese character is normal with phpMyAdmin, but when the PHP page displays the MySQL data, the Chinese character becomes the number, and how many Chinese characters have number?
Reason: There is no code in the PHP Web page to tell MySQL what character set to output Chinese characters.
Workaround:

1. page file Head setting code <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8″/>
2.PHP pages are saved using UTF-8 encoding and can be converted using Notepad or convertz802
3. When creating a new database in MySQL database select UTF-8 encoding is set to UTF-8_UNICODE_CI (Unicode (Multilingual), case-insensitive),
The table tables in the library are sorted and set to Utf-8_general_ci
The collation of each field in the table is set to Utf-8_general_ci
4. When PHP connects to the database, that is, mysql_connect () after joining

Sets the character set of the data utf-8 
mysql_query ("Set names ' UTF8 '");
mysql_query ("Set Character_set_client=utf8");
mysql_query ("Set Character_set_results=utf8");


Attention is UTF8, not utf-8.

If your page code is gb2312, it is SET NAMES GB2312. However, editors strongly recommend Web page encoding, MySQL data table character set, phpMyAdmin all unified use of UTF-8.

The above four points can realize the whole station UTF-8 code, and in the database will not have Chinese garbled.

garbled problem 2: input data with phpMyAdmin error, do not let input or appear garbled
Workaround: This is a setup issue. Please install the latest version of phpMyAdmin or Appserv to open the Phpmyadmin,mysql character set: UTF-8 Unicode (UTF8); MySQL connection proofing should be utf8_unicode_ci ; Organize a column when creating a new database please also select UTF8_UNICODE_CI. Web page character set is also best to choose Utf-8. Utf-8 is the international standard Code, is the trend.

garbled problem 3: In this machine to develop a good MySQL data table, in this machine test everything is normal, but with the site space provider phpMyAdmin upload problems, upload failed. Especially the use of foreign php space.

Solution: First look at the site space provider to provide the phpMyAdmin character set settings, to determine their own data tables and service providers are the same code. In foreign MySQL is not support gb2312, even the latest version of Apache does not support gb2312. If it is because the coding is not uniform, you can reconstruct the data table, of course, with international standard 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.