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

 

 

写在这个文件下面操作

正常模式

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语句_用户信息_02