查询MYSQL数据库,最后显示中文全为?,需要添加什么命令,加在哪,请大家帮忙
<?php
$mysqli = new mysqli("localhost", "root", "root", "school");
mysql_query('set names gb2312');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}$query = "SELECT sname,sc.sno,deptno,cname,cnum,cdept FROM sc,student WHERE sc.sno=student.sno and sc.sno like '".$_GET["s"]."%'";if ($result = $mysqli->query($query)) { /* fetch object array */
while ($obj = $result->fetch_object()) {
printf ("%s %s %s %s %s %s\n", $obj->sname, $obj->sc.sno,$obj->deptno,$obj->cname,$obj->cnum,$obj->cdept);
} /* free result set */
$result->close();
}/* close connection */
$mysqli->close();
?>
<?php
$mysqli = new mysqli("localhost", "root", "root", "school");
mysql_query('set names gb2312');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}$query = "SELECT sname,sc.sno,deptno,cname,cnum,cdept FROM sc,student WHERE sc.sno=student.sno and sc.sno like '".$_GET["s"]."%'";if ($result = $mysqli->query($query)) { /* fetch object array */
while ($obj = $result->fetch_object()) {
printf ("%s %s %s %s %s %s\n", $obj->sname, $obj->sc.sno,$obj->deptno,$obj->cname,$obj->cnum,$obj->cdept);
} /* free result set */
$result->close();
}/* close connection */
$mysqli->close();
?>
然后你查询的页面显示也应该为gb2312编码
在页面起始处加上:
header("Content-Type:text/html;charset=gb2312");
php页要是header("Content-Type:text/html;charset=gb2312");