欢迎光临散文网 会员登陆 & 注册

commentModel.class.php

2023-03-16 11:53 作者:Sweet_Kiko  | 我要投稿

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2023/3/16 0016
* Time: 上午 9:51
*/

class commentModel extends model{
   public function insert(){
       $data['poster']=$_POST['poster'];
       $data['mail']=$_POST['mail'];
       $data['comment']=$_POST['comment'];
       $data['reply']='';
       $data['date']=date('Y-m-d H:i:s');
       $data['ip']=$_SERVER['REMOTE_ADDR'];
       $sql="insert into `comment` set ";
       foreach($data as $k=>$v){
           $sql .="`$k`='$v',";
       }
       $sql=rtrim($sql,',');
       return $this->db->query($sql);
   }

   public function getAll(){
       $order='';
       if (isset($_GET['sort']) && $_GET['sort']=='desc'){
           $order='order by id desc';
       }
       $sql="select `poster`,`comment`,`date`,`reply` from `comment` $order";
       $data=$this->db->fetchAll($sql);
       return $data;
   }
   public function getNumber(){
       $data=$this->db->fetchRow("select count(*) from `comment`");
       return $data['count(*)'];
   }
}

commentModel.class.php的评论 (共 条)

分享到微博请遵守国家法律