博客首页显示

 博客首页收据调用

博客目录:

--admin
--css
--error
--fonts
--images
--js
--lib
  DAOMySQLi.class.php
--template
  index.html
  article.html
博客的文件夹层级目录

 

 

DAOMySQLi.class.php文件内容

<?php
    
    //开发一个dao 数据库操作类[单例模式] 【oop, mysqli, 编程思想】
    class DAOMySQLi {
    
        //dao 应该有哪些属性
        private $_host;
        private $_user;
        private $_pwd;
        private $_dbname;
        private $_port;
        //字符集
        private $_charset;
        //有一个mysqli对象实例
        private $_mySQLi;
        //有个第一个唯一实例的属性
        private static $_instance;

        //该函数完成一个初始化成员属性的任务
        private function _initOption(array $option = array()){
            
            //将传入的 数组 $option 的值赋给 成员属性, 并简单校验
            $this->_host = isset($option['host']) ? $option['host'] : '';
            $this->_user = isset($option['user']) ? $option['user'] : '';
            $this->_pwd = isset($option['pwd']) ? $option['pwd'] : '';
            $this->_dbname = isset($option['dbname']) ? $option['dbname'] : '';
            $this->_port = isset($option['port']) ? $option['port'] : '';
            $this->_charset = isset($option['charset']) ? $option['charset'] : '';

            if($this->_host == '' || $this->_user == '' || $this->_pwd == '' || $this->_dbname == '' || $this->_port == '' || $this->_charset == ''){
                die('你的传入的参数有问题,请重新输入');
            }
        }

        //写一个函数,完成对_mySQLi对象初识化
        private function _initMySQLi(){
            
            //创建mysqli对象实例
            $this->_mySQLi = new MySQLi($this->_host, $this->_user, $this->_pwd, $this->_dbname, $this->_port);

            if($this->_mySQLi->connect_errno){
                die('你的连接失败, 错误信息' . $this->_mySQLi->connect_error);
            }

            //设置字符集
            $this->_mySQLi->set_charset($this->_charset);
        }
        
        //构造函数, 完成初始化
        private function __construct(array $option = array()){

            //echo '<pre> __construct';
            
            //该函数完成一个初始化成员属性的任务
            $this->_initOption($option);
            $this->_initMySQLi();
            
                
        }

        //对外提供一个静态的public方法,可以返回一个唯一的对象实例
        public static function getSingleton(array $option = array()){
            
            //如果还没有创建这个对象实例
            if(!(self::$_instance instanceof self)){
                //创建对象实例, 这里就是构造函数
                self::$_instance = new self($option);
            }
            //返回对象实例
            return self::$_instance;
        }

        
        //防止克隆
        private function __clone(){
        }

        //对外提供一个方法(接口), 完成查询任务(select)
        public function fetchAll($sql = ''){
            
            //为了达到这样的目录
            //1. 立即释放$res
            //2. 需要把这个结果返回给调用文件使用
            //思路是将 $res 记录封装到一个数组中,将数组返回.
            //定义一个空数组,准备装记录
            $arr = array();        
            $res = $this->_mySQLi->query($sql);
            while($row = $res->fetch_assoc()){
                $arr[] = $row;
            }
            //立即释放 $res;
            $res->free();
            return $arr;
        }

        //对外提供一个dml操作的方法(接口), 完成(dml操作)
        public function query($sql = ''){
            
            $res = $this->_mySQLi->query($sql);
            if(!$res){
                echo '<br>执行sql语句失败';
                echo '错误信息'. $this->_mySQLi->error;
                exit;
            }
            return $res;
        }


    }
DAOMySQLi.class.php类文件内容【重点】

 

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>_牛的博客</title>
        <meta name="viewport" content="width=device-width, initial-scale=0.9">
        <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/themify-icons.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/theme.css" rel="stylesheet" type="text/css" media="all" />
        <link href="css/custom.css" rel="stylesheet" type="text/css" media="all" />
    </head>
    <body>

        <div class="main-container">
            <section class="page-title page-title-4 bg-secondary">
                <div class="container">
                    <div class="row">
                        <div class="col-md-6">
                            <h3 class="uppercase mb0">牛的博客nihao </h3>
                        </div>
                        <div class="col-md-6 text-right">
                            <ol class="breadcrumb breadcrumb-2">
                                <li>
                                    <a href="index.html">首页</a>
                                </li>
                            </ol>
                        </div>
                    </div>
                    <!--end of row-->
                </div>
                <!--end of container-->
            </section>

            <section>
                <div class="container">
                    <div class="row">
                        <div class="col-md-9 mb-xs-24">
                          <?php foreach($article_list as $article): ?>
                            <div class="post-snippet mb64">
                                <a href="#">
                                    <img class="mb24" alt="Post Image" src="<?php echo $article['cover'];?>" />
                                </a>
                                <div class="post-title">
                                    <span class="label"><?php echo date('Y年m月d日',$article['create_ad']);?></span>
                                    <a href="#">
                                        <h4 class="inline-block"><?php echo $article['title'];?></h4>
                                    </a>
                                </div>
                                <ul class="post-meta">
                                    <li>
                                        <i class="ti-user"></i>
                                        <span><?php echo $article['title'];?>
                                            <a href="#">泰牛</a>
                                        </span>
                                    </li>
                                    <li>
                                        <i class="ti-tag"></i>
                                        <span>标签
                                            <a href="#">PHP</a>
                                            <a href="#">互联网</a>
                                            <a href="#">PHP7</a>
                                        </span>
                                    </li>
                                </ul>
                                <hr>
                                <p>
                                    <?php echo $article['summary'];?>
                                </p>
                                <a class="btn btn-sm" href="article.html">详细</a>
                            </div>
                          <?php endforeach;?>
                            <!--end of post snippet-->




                            <div class="text-center">
                                <ul class="pagination">
                                    <li>
                                        <a href="#" aria-label="Previous">
                                            <span aria-hidden="true">&laquo;</span>
                                        </a>
                                    </li>
                                    <li class="active">
                                        <a href="#">1</a>
                                    </li>
                                    <li>
                                        <a href="#">2</a>
                                    </li>
                                    <li>
                                        <a href="#">3</a>
                                    </li>
                                    <li>
                                        <a href="#">4</a>
                                    </li>
                                    <li>
                                        <a href="#">5</a>
                                    </li>
                                    <li>
                                        <a href="#" aria-label="Next">
                                            <span aria-hidden="true">&raquo;</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <!--end of nine col-->
                        <div class="col-md-3 hidden-sm">
                            <div class="widget">
                                <h6 class="title">搜索</h6>
                                <hr>
                                <form>
                                    <input class="mb0" type="text" placeholder="关键词" />
                                </form>
                            </div>
                            <!--end of widget-->
                            <div class="widget">
                                <h6 class="title">作者</h6>
                                <hr>
                                <p>
                                    牛,泰牛,身体大,趾端有蹄,头上长有一对角,尾巴尖端有长毛。十二生肖之一。
                                </p>
                            </div>
                            <!--end of widget-->
                            <div class="widget">
                                <h6 class="title">分类</h6>
                                <hr>
                                <ul class="link-list">
                                    <li>
                                        <a href="#">多彩生活</a>
                                    </li>
                                    <li>
                                        <a href="#">Web设计</a>
                                    </li>
                                    <li>
                                        <a href="#">图像库</a>
                                    </li>
                                    <li>
                                        <a href="#">随笔</a>
                                    </li>
                                </ul>
                            </div>
                            <!--end of widget-->
                            <div class="widget">
                                <h6 class="title">最新博文</h6>
                                <hr>
                                <ul class="link-list recent-posts">
                                    <li>
                                        <a href="#">互联网+畅想</a>
                                        <span class="date">September 23, 2015</span>
                                    </li>
                                    <li>
                                        <a href="#">PHP7极速体验</a>
                                        <span class="date">September 19, 2015</span>
                                    </li>
                                    <li>
                                        <a href="#">全栈工程师怎么养成</a>
                                        <span class="date">September 07, 2015</span>
                                    </li>
                                </ul>
                            </div>
                            <!--end of widget-->
                            <div class="widget">
                                <h6 class="title">最新评论</h6>
                                <hr>
                                <ul class="link-list recent-comments">
                                    <li>
                                        <a href="#">高大上</a>
                                        <span class="date">September 23, 2015</span>
                                    </li>
                                    <li>
                                        <a href="#">我要报名</a>
                                        <span class="date">September 19, 2015</span>
                                    </li>
                                </ul>
                            </div>
                            <!--end of widget-->
                        </div>
                        <!--end of sidebar-->
                    </div>
                    <!--end of container row-->
                </div>
                <!--end of container-->
            </section>
            <footer class="footer-1 bg-dark">
                <div class="container">
                    <div class="row">
                        <div class="col-md-6 col-sm-6">
                            <img alt="Logo" class="logo" src="img/logo-light1.png" />
                        </div>
                        <div class="col-md-6 col-sm-6">
                            <div class="widget">
                                <h6 class="title">友情链接</h6>
                                <hr>
                                <ul class="link-list recent-posts">

                                    <li>
                                        <a href="http://www.itbull.cn/">泰牛程序员</a>
                                    </li>
                                    <li>
                                        <a href="http://imeixue.cn/">每学网</a>
                                    </li>
                                </ul>
                            </div>
                            <!--end of widget-->
                        </div>
                    </div>
                    <!--end of row-->
                    <div class="row">
                        <div class="col-sm-6">
                            <span class="sub">&copy; Copyright 2015 - 泰牛程序员</span>
                        </div>
                        <div class="col-sm-6 text-right">

                        </div>
                    </div>
                </div>
                <!--end of container-->
                <a class="btn btn-sm fade-half back-to-top inner-link" href="#top">Top</a>
            </footer>
        </div>
        <script src="js/jquery.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>
template下的index.html文件

 

 

注意事项 时区设置,在php.ini文件中找到data.timezone开启即可

data_default_timezone_set('PRC');

 

posted @ 2020-12-15 14:59  千机楼  阅读(88)  评论(0编辑  收藏  举报