MySQL + PhP garbled

Source: Internet
Author: User

Several people have raised garbled questions, and many others have asked related questions. I have also been confused. Today I understand that the latter is a few simple words.

 

First, check the Chinese garbled characters in the MySQL database?

In case of chaos, first configure the/etc/My. CNF file and rewrite the mysqld and client character sets to UTF-8.

[Client]
# Password = your_password
Port = 3305 #3306
Socket =/tmp/MySQL. Sock
Default-character-set = utf8

[Mysqld]
Port = 3305 #3306
Socket =/tmp/MySQL. Sock
Skip-locking
Key_buffer = 256 m
Max_allowed_packet = 1 m
Table_cache = 256
Sort_buffer_size = 1 m
Read_buffer_size = 1 m
Read_rnd_buffer_size = 4 m
Myisam_sort_buffer_size = 64 m
Thread_cache_size = 8
Query_cache_size = 16 m
Default-character-set = utf8

View the database show variables like '% char %'; view the character set

+ -------------------------- + ------------------------------------------------------------ +
| Variable_name | value |
+ -------------------------- + ------------------------------------------------------------ +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/local/mysql-5.1.34-linux-i686-glibc23/share/charsets/|
+ -------------------------- + ------------------------------------------------------------ +
If not, set character_set_client = UTF-8;
To change the character set.

 

Now, restart MySQL.

 

Then PHP is garbled. It is best to encode the PHP file as utf8.

 

This is the case. If the code is garbled, check whether your browser code is utf8. Let's go here. Although it cannot solve all the garbled issues, but it should be able to solve part of the problem, hoping to be useful to you.

 

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.