<html> <head> <title></title> </head> <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); ?>
显示如下:
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");
本文链接:
收藏随意^^请保留教程地址.