zoukankan      html  css  js  c++  java
  • 生成静态页面

    <?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);
    }
    }

    }
    }
    你所浪费的今天是那些死去的人所奢望的明天,你所厌恶的现在是未来的你所回不去的曾经。
  • 相关阅读:
    strcpy
    Apple Swift中英文开发资源集锦[apple swift resources]
    c/c++指针总结[pointer summary]
    TestPointer
    66. 有序数组构造二叉搜索树[array to binary search tree]
    HDU 2112 HDU Today
    HDU 3790 最短路径问题
    HDU 2544 最短路
    模拟赛 Problem 3 经营与开发(exploit.cpp/c/pas)
    模拟赛 Problem 2 不等数列(num.cpp/c/pas)
  • 原文地址:https://www.cnblogs.com/stj123/p/9921217.html
Copyright © 2011-2022 走看看