MySQL Chinese language cannot be read.

Source: Internet
Author: User
MySQL Chinese cannot read ...

This is how the MySQL database is encoded

This is the result of the background data, do not use Chinese words will normally write to the background, the use of Chinese words can not be written. (Watch the last few rows of data)
If you write to the database directly in Chinese, it will be displayed.
PHP Code section
if (Isset ($_post[' B1 '))
{
$username =$_post["username"];
$message =$_post["message"];
if ($username = = "")
{
echo "";
if ($message = = "")
{
echo "";
}
}
Else
{
$addtime =date ("y-m-d h:m:s");
$id =mysql_connect ("localhost", "root", "1234");
mysql_select_db ("Gbook", $id);
$query = "INSERT into message (author,addtime,content,reply) VALUES (' $username ', ' $addtime ', ' $message ', ') ';
$result =mysql_query ($query, $id);
Mysql_close ($id);
echo "result=". $result;
echo "";
}
}
------Solution--------------------

$username =iconv (' gb2312 ', ' utf-8 ', $_post["username"]);
$message =iconv (' gb2312 ', ' utf-8 ', $_post["message"]);

------Solution--------------------
Database encoding is UTF8
If you write to the database directly in Chinese, it will be displayed. (chasing after a line)
phpMyAdmin will do coding settings, naturally no problem
Your code is not coded, so it is normal for the problem to occur!
When the file encoding is GBK (ANSI under Windows) should be
mysql_query (' Set names GBK ');
When the file encoding is utf-8, it should be
mysql_query (' Set names UTF8 ');


  • 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.