age."");}mysql_close($conn);?> 显示如下:Resource id #1dd:54ddd:8??:15???:25??:32 mysql编码:utf8,GBK都试过了。mysql">
当前位置:Gxlcms > PHP教程 > PHP中文乱码问题及解决方法_PHP教程

PHP中文乱码问题及解决方法_PHP教程

时间:2021-07-01 10:21:17 帮助过:15人阅读









$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
");
while($row = mysql_fetch_object($rs)){
print ($row->name.":".$row->age."
");
}
mysql_close($conn);
?>

  显示如下:

Resource id #1
dd:54
ddd:8
??:15
???:25
??:32

  mysql编码:utf8,GBK都试过了。mysql font 和命令行显示都正确。

  问题补充:

  乱码:

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

  这几行,数据库里的值是汉字.显示出来的是问号.

  解决办法:

  在$rs=mysql_db_query("lib","select * from mytb",$conn);

  前面加上

  mysql_query("set names gb2312");或者mysql_query("set names gbk");

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632501.htmlTechArticlehtml head title/title /head body ?php $mysql_server_name='localhost'; $mysql_username='root'; $mysql_password='000000'; $mysql_database='lib'; $conn=mysql_connect($mysql_server_nam...

人气教程排行