How to solve the problem of inserting MySQL database garbled characters in UbuntuPHP

Source: Internet
Author: User
Environment: The methods below UbuntuLinux have been tested by myself, which can solve the problem of inserting MySQL database garbled characters in UbuntuPHP. 1. use utf8 for database storage whenever possible (modify/etc/my. cnf: Add default-character-set = utf8 in the [mysqld] segment (convert existing databases to UTF8 format first) 2. before the PHP program queries the database, execute mysql_query ("setnamesxxxx"); where xx

Environment: Ubuntu Linux
The following methods have been tested by myself and can solve the problem of garbled characters in Ubuntu PHP inserting MySQL database.

1. Use utf8 for database storage as much as possible (modify/etc/my. cnf and add default-character-set = utf8 in the [mysqld] segment) (convert existing databases to UTF8 format first)

2. before the PHP program queries the database, execute mysql_query ("set names xxxx"). xxxx indicates the code of Your webpage (charset = xxxx). If charset = utf8 In the webpage, then xxxx = utf8. If charset = gb2312 In the webpage, xxxx = gb2312

Almost all WEB programs have a piece of public code to connect to the database. Put it in a file and add mysql_query ("set names") to the file.

3. PHPMyAdmin does not need to be modified.

4. Note that to ensure the actual encoding of the webpage (encoding in the Windows save dialog box) and its declared encoding (charset = ?) Yes. use tools such as DW for Web pages.

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.