How to solve MySQL garbled characters in PHP _ PHP Tutorial

Source: Internet
Author: User
Related Solutions for displaying MySQL garbled characters in PHP. PHP displays MySQL garbled characters. 1. when PHPmyAdmin is used to operate MySQL databases, the Chinese characters are displayed normally. but when MySQL data is displayed on the PHP webpage, all Chinese characters are changed? . Symptom: use PHPmyAdmin to enter a Chinese characterPHP displays MySQL garbled characters. 1. when PHPmyAdmin is used to operate MySQL databases, the Chinese characters are displayed normally. but when MySQL data is displayed on the PHP webpage, all Chinese characters are changed? .

Symptom: it is normal to use PHPmyAdmin to input Chinese characters. but when MySQL data is displayed on the PHP webpage, the Chinese characters become? And how many Chinese characters are there? . Many trainees have encountered this problem, especially after the latest Appserv version is installed. For this reason, many students abandoned PHP and changed to ASP.

Cause: no code is used on the PHP webpage to tell MySQL which character set to output Chinese characters.

★PHP displays MySQL garbled code solution: this is not garbled. you only need to add the following code to the PHP webpage header to tell MySQL to output Chinese characters in UTF8 encoding.

 
 
  1. <? Mysql_query ("set names UTF8");?>
  2. You can also insert the above code snippet directly in the PHP code section on the webpage (that is, remove the two ends <?> ). For example, if you use Dreamweaver to connect to the database, the connection code in the header can be
  3. <? Php require_once ('ons ONS/connmessage. php');?> Add the code to make it
  4. <?
  5. Php require_once ('ons ONS/connmessage. php ');
  6. Mysql_query ("set names UTF8 ");
  7. ?>

Note: If your webpage code is gb2312, it is set names GB2312. However, editors strongly recommend that UTF8 be used for webpage encoding, MySQL data table character set, and PHPmyAdmin. For the reason, see section 2nd of chapter 1 of the PHP Tutorial on this site.

PHP displays MySQL garbled 2. an error occurred when using PHPmyAdmin to input data. do not input or garbled characters

★PHP displays MySQL garbled code. Solution: This is a setup problem. Install the latest PHPmyAdmin or Appserv, open PHPmyAdmin, MySQL character set: UTF-8 Unicode (utf8); MySQL connection proofread should be utf8_unicode_ci; when creating a new database, sort the column as utf8_unicode_ci. Utf8 is also recommended for Web character sets. Utf8 is an international standard code and a trend. For how to change the webpage code, see section 2nd of chapter 1 of the PHP Tutorial on this site.

PHP displays MySQL garbled 3. MySQL data table developed on the local machine, test everything on the local machine is normal, but the PHPmyAdmin file provided by the website space provider fails to be uploaded. Especially when using PHP space outside China.

★PHP displays MySQL garbled codes. Solution: First, check The PHPmyAdmin character set provided by the website space provider and determine that the data table and space created by the user are encoded in the same code. MySQL does not support gb2312 in foreign countries, and even the latest Appserv does not support gb2312. If the encoding is not uniform, you can recreate the data table. of course, the international standard UTF8 is used.


Why. when I use PHPmyAdmin to operate MySQL databases, Chinese characters are displayed normally, but when I use PHP web pages to display MySQL data, all Chinese characters are changed? . Symptom: use PHPmyAdmin to input Chinese...

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.