dsz
注册会员

UID 74660
精华
0
积分 105
帖子 51
金钱 105 喜悦币
威望 0
人脉 0
阅读权限 20
注册 2006-6-7
状态 离线
|
数据库只能读英文,不能读汉文,及时间值
这样的一段代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Web Database Sample Index</title>
</head>
<body bgcolor="#999999">
<h2>Data from tb1</h2>
<?php
$host="localhost";
$user="dszphp";
$password="dszphp";
$dbname="pet";
mysql_connect("$host","$user","$password") or die("无法连接mysql服务器");
$db = mysql_select_db("$dbname") or die("无法连接数据库!");
$sql ="select * from pet";
$query = mysql_db_query($dbname,$sql);
if ($query){
echo "Found these entries in the database:<br><p></p>";
echo "<table width=90% align=center border=1></tr>
<td align=center bgcolor=#00ffff>Name</td>
<td align=center bgcolor=#00ffff>Owner</td>
<td align=center bgcolor=#00ffff>Species</td>
<td align=center bgcolor=#00ffff>S_sex</td>
<td align=center bgcolor=#00ffff>Birth</td>
<td align=center bgcolor=#00ffff>Death</td>
</tr>";
while ($r = mysql_fetch_array($query)){
$name = $r["name"];
$owner = $r["owner"];
$species = $r["species"];
$s_sex = $r["s_sex"];
$Birth = $r["Birth"];
$Death = $r["Death"];
echo "<tr>
<td>$name</td>
<td>$owner</td>
<td>$species</td>
<td>$s_sex</td>
<td>$Birth</td>
<td>$Death</td>
</tr>";
}
echo "</table>";
}else{
echo "No data.";
}
?>
</body>
</html>
运行后,数据库里的值如果是英文的都可以读出来,中文的话,如“男”读成“鐢?/td>”,如果表示时间的字段值,就什么都没有一片空白,这是为什么。请指教!!!
|
|