Perfect solution to the problem of MySQL Chinese garbled

Source: Internet
Author: User
Tags connection pooling ini mysql client root directory
mysql|sql| Solution | problem | Chinese garbled

*mysql (best combination with PHP) The reason of Chinese garbled

MySQL (and the best combination of PHP) will appear in Chinese garbled reasons are the following:

-mysql (the best combination of PHP) server itself set problems, such as still stay in Latin1

-mysql (the best combination of PHP) and the language setting problem for table (including character and collation)

-line-language setup issues for client programs (such as PHP)

In the previous two articles, I have described how to set the Character/collation of MySQL (the best combination of PHP) server/table.

The next thing you need to do is add a few caveats:
*mysql (best combination with PHP) Chinese garbled to win the solution

1, MySQL (and the best combination of PHP) will start reading a preset config file, the general name is My.ini, and it will go to the following two locations to find this file:

C:\windows\my.ini is also the installation directory of the operating system, it may be C:\winnt\my.ini
C:\:MY.CNF is the root directory of C disk

Note that the file suffix in different locations is not the same, which is not particularly emphasized in previous articles, so I was in a more complex way to directly re-register MySQL (and the best combination of PHP) to the service, and where to specify the location of the My.ini.

2, the contents of the My.ini are:
[The best combination of MySQL (and PHP) d]
Default-character-set=utf8

[Client]
Default-character-set=utf8
init_connect= ' SET NAMES UTF8 '

where MySQL (and the best combination of PHP) d is to specify the server startup to use the language, but if the setting for UTF8 may make a lot of English software is not happy, such as Oscommerce/mediawiki, so it is recommended to set up latin1.

The following client is set to use when the client line, but unfortunately this setting is not every client will bird it, basically only MySQL (and PHP with the best combination) of their own home programs, such as MySQL (and PHP with the best combination). exe, MySQL (the best combination of PHP) D.exe, MySQL (the best combination of PHP) Admin.exe or MySQL (the best combination of PHP) control Center This program will read this profile and then switch to the UTF8 connection.

Note: Thanks to b6s to provide a second line of instructions, is said to be more than a PHP program to set the connection setting faster, which should also be able to solve the problem phpMyAdmin can not correctly display Unicode Chinese ( But amfphp to do not eat this set, must obediently self set the language of the family only line

But most of the engineers should be the php/jsp (the Sun Enterprise Application preferred) program to connect, this time naturally will not read this setting and continue to use the default language-Latin1.

This is also the place where most of our letters and friends died.

Normally I would use a separate file to handle the connection settings for MySQL (the best combination of PHP), such as:
PLAIN TEXT
?
Database connection details.
$host = "localhost";
$link = MySQL (with the best combination of PHP) _connect ($host, "xxx", "xxx");
MySQL (the best combination of PHP) _query ("SET NAMES ' utf8");
MySQL (the best combination with PHP) _select_db ("Your_table_name_here", $link);
?>

Please note that in the fifth line of MySQL (and PHP with the best combination) _connect, add a "set names ' UTF8" instruction to tell MySQL (and the best combination of PHP) that the connection connection content will be used UTF8, After this setting, most of the problems are usually solved.

It can be inferred from here that if you use some custom connection pooling mechanism, you should remember to set the UTF8 immediately after each new connection is created.

This set of settings after several days of repeated testing (using Chinese, Jane, Japanese, Korean) has been confirmed that there is no garbled or some words into the "mouth."

Example: The participants enter these words "no way" if they can go right into MySQL (the best combination of PHP) and then read it, that is Chinese no problem, if read out and become "mouth" word that is the revolution has not succeeded comrades still need to work hard ... Orz

Of course, I also by the way to verify the Flex2-amfphp-php-mysql (and the best combination of PHP) back and forth ResultSet also no longer have Chinese garbled problem, you can ease the use of it.



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.