<?php ob_start(); if(file_exists('list.html')){ //直接拿来用 $content = file_get_contents("list.html"); echo $content; die; } header("content-type:text/html;charset=utf-8"); //链接数据库 $link = mysqli_connect("127.0.0.1",'root','root','08e'); //设置字符集 mysqli_query($link,'set names utf-8'); //拼接sql $sql = "select * from user"; //执行 $res = mysqli_query($link,$sql); while($a = mysqli_fetch_assoc($res)){ $data[] = $a; } ?> <table> <tr> <th>ID</th> <th>账号</th> <th>密码</th> <th>状态</th> </tr> <?php foreach($data as $k=>$v){ ?> <tr> <td><?php echo $v['id'];?></td> <td><?php echo $v['username'];?></td> <td><?php echo $v['password'];?></td> <td><?php if($v['status']==1){ echo "启用"; }else{ echo "禁用"; } ?></td> </tr> <?php } ?> </table> <?php //获取缓存内容 $content = ob_get_contents(); //写入缓存文件 file_put_contents("list.html",$content); ?>