码迷,mamicode.com
首页 > 数据库 > 详细

php tp5 语句后面链式追加sql语句

时间:2020-03-25 10:56:49      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:code   des   ret   function   xxx   mic   where   pre   use   

技术图片

 

 

写在这个文件下面操作

正常模式

db(‘user‘)->where(‘status‘,1)->select(); 查询状态为1的用户信息

在 Query.php下新增函数
public  function unionWhere(){
        return $this->where(‘status‘, 1);
    }

 链式追加

db(‘user‘)->unionWhere()->select(); 查询状态为1的用户信息

还可以传参配合switch
db(‘user‘)->applySql(1)->select(); 查询状态为1的用户信息
//动态追加排序条件
    public function applySql($type)
    {
        switch ($type) {
            case 1:
                return $this->unionWhere();
                break;
            default:
                return $this->sortActive(); //最后回复排序
                break;
        }
    }
    //最新帖子排序
public function unionWhere(){
        return $this->where(‘status‘, 1);
    }
//最后回复排序 
public function sort2id()
{
return $this->order(‘id‘, ‘desc‘);
}

 还可以直接改写 select/delete/xxx 等结尾函数,适用于SAAS模式,如:每次查询带 where (sid,xxx);

  技术图片

 

php tp5 语句后面链式追加sql语句

标签:code   des   ret   function   xxx   mic   where   pre   use   

原文地址:https://www.cnblogs.com/wdw31210/p/12564297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!