<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>数据库读取实例</title>
</head>
<body>
<?php
@mysql_connect("localhost","root") or die("数据库服务器连接失败");
@mysql_select_db("resStore") or die("数据库不存在或者不可用");
$query = "Select * from jos_users";
$rs = @mysql_query($query) or die("SQL查询语句执行失败");
$num_rows = mysql_num_rows($rs);
echo "Total Rows :$num_rows";
echo "<table border=\"1px\">";
echo "<tr>";
//输出数据表的标题
for ($j2 = 0; $j2 < mysql_num_fields($rs); $j2++) {
echo "<th>".mysql_field_name($rs,$j2)."</th>";
}
echo "</tr>";
for ($i = 0; $i < $num_rows; $i++) {
echo "<tr>";
$row = mysql_fetch_array($rs,MYSQL_NUM);
for ($j = 0; $j < mysql_num_fields($rs); $j++) {
echo "<td>$row[$j]</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>