1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| <?php
$con = mysql_connect("localhost","root","root");
if(!$con){ dir("Database Connect Error".mysql_error()); }else{ mysql_query( "set names utf8" );
mysql_select_db("websafe",$con);
$result = mysql_query("select * from teacher"); echo "Show teachers in table<br />"; echo "<table border='2' width='300'>" <tr><th>id</th><th>name</th><th>sex</th><th>addr</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 "<td>".$row["addr"]."</td>"; echo "</tr>"; } echo "</table>"; }
# 关闭数据库 mysql_close($con); ?>
|