php tp5 语句后面链式追加sql语句
发布时间:2023-01-12 10:35:29 326
相关标签: # php# 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);
文章来源: https://blog.51cto.com/u_15702997/5431152
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报