$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");