当前位置:Gxlcms > 数据库问题 > php tp5 语句后面链式追加sql语句

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

时间:2021-07-01 10:21:17 帮助过:71人阅读



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   

人气教程排行