zoukankan      html  css  js  c++  java
  • tp5框架 model层 增删改查

    <?php
    namespace appindexmodel;
     
    use thinkModel;
     
    class User extends Model
    {
     
        /**
         * 添加数据
         * @param array $data
         * @return int  id值
         */
        public function insert($data)
        {
     
            $result =  $this ->save($data);
     
            if($result===false){
     
                return false;
            } else{
     
                return $this->id;
            }
        }
     
        /**
         * 根据条件修改
         * @param array $where
         * @param array $data
         * @return id  id值
         */
        public function updateByWhere($where,$data)
        {
     
     
            $result = $this->where($where)->update($data);
            if($result===false){
                return false;
            } else{
                return true;
            }
     
        }
     
        /**
         * 根据条件删除
         * @param array $where
         * @return id  id值
         */
        public function deleteByWhere($where)
        {
            return $this->where( $where )->delete();
        }
     
        /**
         * 根据条件统计
         * @param array $where
         * @return num  条数
         */
        public function countWhere($where){
     
            return $this->where($where)->count();
     
        }
     
     
        /**
         * 根据属性获取一行记录
         * @param array $where
         * @param string $fileds
         * @return array 返回一维数组,未找到记录则返回空数组
         */
        public function findByAttributes($where = array(),$fileds="*")
        {
     
            return $this->field($fileds)->where( $where )->find();
        }
     
        /**
         * 根据条件查询获得数据
         * @param array $where
         * @param string $fileds
         * @return array 返回二维数组,未找到记录则返回空数组
         */
        public function findAllByWhere($where = array(),$fileds="*",$order="id desc")
        {
     
            return $this->field($fileds)->where( $where )->order($order)->select()->toArray();
        }
        /**
         * 查询全部数据有分页查询
         * @param array $where
         * @param string $fileds
         * @param string $offset
         * @param string $num
         * @param string $order
         * @return array 返回二维数组,未找到记录则返回空数组
         */
        public function loadAllData($where,$offset=0,$num=1,$order="id desc"){
     
          return $this->where($where)->order($order)->limit("$offset,$num")->select()->toArray();
     
       }
    }
  • 相关阅读:
    log4js 2.X版本配置详解
    ping -c 3 localhost
    children_process.exec 执行 ping命令报错
    淘宝双十一为什么会出现通道拥挤?
    'ascii' codec can't decode byte 0xd6 in position 0
    window 安装grunt
    display:none与visible:hidden的区别 slideDown与
    ztree-demo 2
    ztree-demo
    技术总结PHP+微信
  • 原文地址:https://www.cnblogs.com/panziwen/p/12490450.html
Copyright © 2011-2022 走看看