<?php
$con=mysql_connect("localhost","root","");
if(!$con){
die("连接失败".mysql_error);
}
mysql_select_db("school",$con);
//select语句用于从数据库中选取数据
$result=mysql_query("SELECT * FROM student");
//打印该表中所有数据
/*
while($row=mysql_fetch_array($result)){
echo $row['Name']." ".$row['Sex'];
echo "<br/>";
}
*/
//使用表格打印出该表中所有数据
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Sex</th>
</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>".$row['ID']."</td>";
echo "<td>".$row['Name']."</td>";
echo "<td>".$row['Sex']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>