1、显示数据库中信息
数据调用模式图示,list.php展示数据库中信息
<?php
$conn=mysql_connect("localhost","用户名","密码") or die(mysql_error);
//链接数据库,如果链接出错,显示错误信息
mysql_query("set names utf8");
//设置编码格式
mysql_select_db("数据库名",$conn);
//选择数据库
$sql="select * from 表名";
//sql语句
$res=mysql_query($sql,$conn);
echo "<table border='1' width='700px'>";
echo "<tr>";
echo "<td>员工id</td><td>员工姓名</td><td>员工等级</td><td>员工邮箱</td><td>员工薪水</td></tr>";
while($row=mysql_fetch_assoc($res)){
echo "<tr>";
echo "<td>" .$row['id']."</td><td>" .$row['name']."</td><td>" .$row['grade']."</td>
<td>" .$row['emil']."</td><td>" .$row['salary']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($res); //释放资源
mysql_close($conn); //关闭连接
?>
代码运行结果展示: