• php生成静态页面


    <?php
    /**
     * Created by PhpStorm.
     * User: s
     * 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);
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    Tarjan专题
    Catalan数
    状压DP
    威尔逊定理证明:
    【fzoj 2376】「POJ2503」Babelfish
    Android 源码
    Android实现推送方式解决方案
    Android apk 签名
    圆角的实现
    Android 资源
  • 原文地址:https://www.cnblogs.com/stj123/p/12323303.html
Copyright © 2020-2023  润新知