PHP query MySQL, Chinese data, different ways to add the same data to display different solutions

Source: Internet
Author: User
PHP query MySQL, Chinese data, different ways to add the same data unexpectedly display different
Hi
Let me start with my situation. A novice in PHP.
– Phenomenon
In the output page, I have added the , I also added a query to MySQL.
mysql_query ("Set character set UTF8");
mysql_query ("SET NAMES ' UTF8 '");
Some Chinese can show, some can't.

---garbled display of the process and code
The database and text fields in my phpmyadmin are set with Utf8_unicode_ci.

I manually add the Chinese to the database via phpMyAdmin and then directly execute the
mysql_query ("Set character set UTF8");
mysql_query ("SET NAMES ' UTF8 '");
$rs = $db->query ("SELECT * from book");
Display garbled.

---normal display of code and unexpected results
mysql_query ("Set character set UTF8");
mysql_query ("SET NAMES ' UTF8 '");
$rs 2 = $db->exec ("INSERT into ' lalabook '. ' Book ' (' BookName ', ' Bookdes ') VALUES (' Creeps ', ' small ') ');
$rs = $db->query ("SELECT * from book");
The data that I inserted can be displayed normally. But one problem is that when I look through phpMyAdmin to see the data I've inserted, it's garbled.
----
So I'm not sure what the cause of this is, is not that I later insert data through the code. No more phpmyadmin inserted.


------Solution--------------------
Execute SET NAMES ' UTF8 ' directly within phpMyAdmin and then select .... Out of the results?
phpMyAdmin is also required to set the link encoding.
------Solution--------------------
is not a problem with the encoding of the file itself
------Solution--------------------
is a virtual host, everything is normal.

The user submits the utf8,php operation to the storage, the storehouse is possible.

Phpadmin garbled is because mysql_server code General Service providers are Latin, but the service providers generally ensure that connenct/client/result is UTF8, that is, the data is UTF8 encoding, storage time is Latin, So go to phpadmin to see the PHP operation will be garbled.

In addition, in the Phpadmin to execute the SQL inserted data, in PHP read the time will be garbled, this problem is very magical, I did not see phpMyAdmin page is what encoding.

Bottom line: Set the library, table, column encoding is all UTF8-UNICODE-CI, and then the data out of storage are used UTF8 encoding, do not care about phpadmin data when garbled, will not affect users.
------Solution--------------------
Coding is commonly used in UTF8-GENERAL-CI
Not only the table to pass one, to unify the total of all around
One is: The database type, which includes, database, table, fields are unified three, you can check
The second is: the file encoding type, if you use DW or editplus can see the page encoding, different need to modify
The third is: when accessing the database settings are set NAMES UTF8;
Four is: the browser display mode, both
This must be uniform everywhere, otherwise there may be problems
  • 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.