A problem of Chinese garbled in PHP and its solving method

Source: Internet
Author: User
Tags command line mysql code php and
<title></title>
<body>
<?php
$mysql _server_name= ' localhost ';
$mysql _username= ' root ';
$mysql _password= ' 000000 ';
$mysql _database= ' Lib ';
$conn =mysql_connect ($mysql _server_name, $mysql _username, $mysql _password, $mysql _database);
$sql = "Select Name,age from MYTB";
Print ($conn);
$rs =mysql_db_query ("Lib", "select * from MYTB", $conn);
Print ("\n<br>");
while ($row = Mysql_fetch_object ($rs)) {
Print ($row->name. ":". $row->age. " <br> ");
}
Mysql_close ($conn);
?>

The display is as follows:

Resource ID #1
dd:54
Ddd:8
?? : 15
??? : 25
?? : 32

MySQL code: UTF8,GBK have tried. MySQL font and command line display are correct.

Question added:

Garbled:

??? : 15
??? : 25
?? : 32

In these lines, the value in the database is Chinese characters. The question mark is displayed.

Solution:

In $rs=mysql_db_query ("Lib", "select * from MYTB", $conn);

Before adding

mysql_query ("Set names gb2312") or mysql_query ("Set names GBK");

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.