Description of the MySQL Chinese garbled Solution

Source: Internet
Author: User

The following articles mainly describe the MySQL Chinese garbled solution. MySQL Chinese garbled characters often occur in actual applications, causing a lot of inconvenience in actual operation, the following article introduces the MySQL Chinese garbled solution.

Over the past few months, I have been writing to ask questions about compatibility with MySQL (the best combination with PHP) in Chinese, so I have the opportunity to see various connection methods and programs used by many players, it's too eye-catching.

Recently, many frameworks written last year cannot be used because of converting to flex 2 as a development platform and rewriting some products. However, some libraries that specifically process multiple languages also become invalid, as a result, I have to face this problem again, so I would like to take this opportunity to organize some new experiences.

MySQL (the best combination with PHP) Causes of 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 of PHP and MySQL) 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 (the best combination with PHP) MySQL Chinese garbled Solutions

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]

 
 
  1. default-character-set=utf8   
  2. [client]    
  3. default-character-set=utf8   
  4. 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 naturally 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:

 
 
  1. PLAIN TEXT   
  2. <?   
  3. //database connection details.   
  4. $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 "set names 'utf8'" command is added to 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

Of course, I also verified flex2-amfphp-php-MySQL (the best combination with PHP) back-and-forth resultset will no longer have MySQL Chinese garbled issues, you can use it with peace of mind.

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.