php页面显示数据库查询结果是乱码。查了很多资料不能解决。有人碰到过类似问题吗?求高人指点。不胜感谢!
现将代码贴出来
顺便说一句,执行的时候显示下面两行错误。
Warning: mssql_query() [function.mssql-query]: message: 'names' ????????? SET ???䡣 (severity 15) in D:\AppServ\www\a.php on line 20Warning: mssql_query() [function.mssql-query]: Query failed in D:\AppServ\www\a.php on line 20
<html>   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>   
<body>   
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-5-25
 * Time: 上午10:00
 */echo "欢迎使用PHP!!";
echo "<br>";
$conn=mssql_connect('localhost','sa','yxz');
mssql_select_db('game',$conn);
mssql_query("SET names gb2312");
//query语句
 $Query='select * from userabc';
$AdminResult=mssql_query($Query);
//输出结果
$Num=mssql_num_rows($AdminResult);
for($i=0;$i<$Num;$i++)
{
    $Row=mssql_fetch_array($AdminResult);
    echo($Row[0]);    echo($Row[1]);    echo($Row[2]);    echo($Row[3]);    echo("<br>");}?>
</body>
</html>

解决方案 »

  1.   


    //输出时转换编码 什么编码看情况而定
    while($row = mssql_fetch_row($result)){
        echo iconv('UTF-8','GB2312',$row[0]);
    }
    试试把这个去掉 mssql_query("SET names gb2312"); 
    mssql用的少,不知道这句行不行得通,先去掉试试。
      

  2.   

    估计你数据库使用utf8编码
    而页面使用charset=gb2312
    所以会显示乱码首先加入
    @mssql_query("SET NAMES UTF8",$conn);然后php文件修改为utf8编码,meta都修改为utf8
    <meta http-equiv="content-type" content="tex/html;charset=utf-8">