生成静态页面

<?php
/**
* Created by PhpStorm.
* User: song tong jing
* Date: 2018/11/3
* Time: 8:33
*/
class PdoClass
{
protected $_pdo;
public function __construct()
{
$this->_pdo = new PDO("mysql:host=127.0.0.1;dbname=student","root","root");
}
//分页
public function fen_ye($page)
{
$count1=$this->_pdo->query("select count(*) from news")->fetchColumn();
$tiao=3;
$zong_page=ceil($count1/$tiao);
// return $zong_page;
$limit=($page-1)*$tiao;
$sql="select * from news limit $limit, $tiao";
$re= $this->_pdo->query($sql)->fetchAll();
$show['shou_page']=1;
$show['shang_page']=$page-1<1?1:$page-1;
$show['xia_page']=$page+1>$zong_page?$zong_page:$page+1;
$show['zong_page']=$zong_page;
$list=['re'=>$re,'show'=>$show];
return $list;
}
//查询多条
public function sele($title='')
{
if(!empty($title))
{
$sql="select * from news where title LIKE '%$title%'";
return $this->_pdo->query($sql)->fetchAll();
}
$sql="select * from news";
return $this->_pdo->query($sql)->fetchAll();
}
//查询单条
public function getsel($id)
{
$sql="select * from news where id='$id'";
return $this->_pdo->query($sql)->fetch();
}
//删除
public function delete($id)
{
$sql="delete from news where id=$id";
$this->_pdo->exec($sql);
return true;
}
//添加
public function add($title,$content,$time)
{
$sql="insert into news VALUES (null,$title,$content,$time)";
$this->_pdo->exec($sql);
return true;
}
//修改
public function update($id,$title,$content)
{
$sql="update news set title='$title',content='$content' where id='$id'";
$this->_pdo->exec($sql);
return true;
}
//静态化
public function obhtml($id,$title,$content)
{
ob_start();
include "show.html";
$text=ob_get_clean();
$shu_ru='./html/'.$id.'.html';
if(file_exists($shu_ru))
{
$filec_time=filectime($shu_ru);//文件创建时间
if(time()-$filec_time<20)//没有过期
{
echo "自动生成静态页面";
file_put_contents($shu_ru,$text);
}
else//过期
{
unlink($shu_ru);//删除过期文件
ob_start();
echo "这是过期后生成的静态页面";
file_put_contents($shu_ru,$text);
}
}

}
}
你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
原文地址:https://www.cnblogs.com/stj123/p/9921217.html