The following articles mainly describe how to solve MySQL Chinese garbled characters, description of the causes of Chinese garbled characters in the MySQL database and the notes worth attention in the process of resolving MySQL Chinese garbled characters. The following describes the specific content of the article.
MySQL Chinese garbled characters
MySQL (the best combination with PHP) causes Chinese garbled characters, which are similar to the following:
MySQL (the best combination with PHP) server settings, for example, still stuck in latin1
MySQL (the best combination with PHP) table language settings (including character and collation)
Connection language settings for client programs (such as php)
In the previous two articles, we have introduced how to set the character/collation of the server/table for MySQL (the best combination with PHP.
Next, you only need to pay attention to the following points:
MySQL Chinese garbled code Solution
1. MySQL (the best combination with PHP) will read a preset config file at startup, which is generally named my. ini and will search for this file in the following two locations:
C: \ windows \ my. ini is the installation directory of the job system. It may also be C: \ winnt \ my. ini.
C: \: my. cnf is the root directory of C disk.
Note that the files in different locations are different from suffix, which is not particularly emphasized in previous articles. Therefore, I used a more complex method to directly repeat MySQL (the best combination with PHP) register to the service and specify my. ini location.
2. The content in my. ini is:
- [MySQL (the best combination with PHP) d]
- Defaultcharacterset = utf8
- [Client]
- Defaultcharacterset = utf8
- Init_connect = 'set NAMES utf8'
Among them, MySQL (the best combination with PHP) d is the language used when the server is started, but if it is set to utf8, it may make many English software unhappy, such as osCommerce/mediaWiki, therefore, we recommend that you set it to latin1.
Examples, mysql(and php d))))))))adminadminadminadminadminadminadminadminadminadminadmin.exe or MySQL (the best combination with PHP) Control Center, which will read this configuration file and then use utf8 to connect.
Note: Thanks to b6s sang for providing the second line of instruction, it is said that it is faster than a php program to set connection setting, this should also solve the problem that phpmyadmin cannot correctly display unicode Chinese characters (however, amfphp does not use this set, so you must set your own language)
However, most engineers should write their own php/jsp (the preferred choice for SUN Enterprise Applications) programs to connect. At this time, they will not read this setting and continue to use the default language latin1.
This is exactly where I sent a letter to my friend.
Usually I will use an independent file to process MySQL (the best combination with PHP) connection settings, for example:
- PLAIN TEXT
- <?
- // Database connection details.
- $ Host = "localhost ";
- $ Link = MySQL (the best combination with PHP) _ connect ($ host, "xxx", "xxx ");
- MySQL (the best combination with PHP) _ query ("set names 'utf8 '");
- MySQL (best combination with PHP) _ select_db ("your_table_name_here", $ link );
- ?>
Note that the command "set names 'utf8'" is added to the link on the fifth line after MySQL (the best combination with PHP) _ connect, tell MySQL (the best combination with PHP) That utf8 is used for connection content after connection. After such setting, most problems can be solved.
It can be inferred from this that if you use a custom connection pooling mechanism, you should remember to set it to utf8 immediately after each new connection.
After a few days of reverse tests (using Chinese characters such as traditional Chinese, simplified Chinese, Japanese, and Korean), this group of settings has confirmed that there will be no garbled characters or some words will become "Mouth ".
Example: If the words entered by the examinee are "no choice" and can be read again after they are correctly entered into MySQL (the best combination with PHP), it is no problem in Chinese, if the words become "Mouth" after reading it, it means that the revolution is not yet successful. comrades still need to work hard... orz.