<?php
$conn=mysql_connect('localhost','root','123456');
mysql_set_charset("utf8");
mysql_select_db("db1");
$sql="select * from test";
$result=mysql_query($sql);
if($result==false){
echo "sql语句执行失败,输出错误信息为".mysql_error();
}else{
echo "<table border='1'>";
//mysql_fetch_array()函数的作用类似foreach对数组的作用:遍历(结果集)
//它每次去的结果集的“一行数据”,并“装入”到数组 $record 中
//该数组的下标就是该select的字段名,值就是对应行的数据值
while($arr=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$arr['id']."</td>";
echo "<td>".$arr['grade']."</td>";
echo "<td>".$arr['name']."</td>";
echo "<td>".$arr['time']."</td>";
echo "</tr>";
}
echo "</table>";
}
?>