TP5 where多条件查询

Where 条件表达式格式为:

$where[‘字段名’] = array(‘表达式’, ‘操作条件’);

$res = Db::name(‘tablename’)->where($where)->select();

| SQL运算符 | sql运算符 | 例子 |实际查询条件

TP运算符SQL运算符例子实际查询条件
eq=$where[‘id’] = array(‘eq’,100);等效于:$map[‘id’] = 100;
neq!=$where[‘id’] = array(‘neq’,100);id != 100
gt>$where[‘id’] = array(‘gt’,100);id > 100
egt>=$where[‘id’] = array(‘egt’,100);id >= 100
lt<$where[‘id’] = array(‘lt’,100);id < 100
elt<=$where[‘id’] = array(‘elt’,100);id <= 100
likelike$where(‘username’) = array(‘like’,’%admin%’);username like ‘%admin%’
betweenbetween and$where[‘id’] = array(‘between’,‘1,8’);id BETWEEN 1 AND 8
not betweennot between and$where[‘id’] = array(‘not between’,‘1,8’);id NOT BETWEEN 1 AND 8
inin$where[‘id’] = array(‘in’,‘1,5,8’);id in(1,5,8)
not innot in$where[‘id’] = array(‘not in’,‘1,5,8’);id not in(1,5,8)
and(默认)and$where[‘id’] = array(array(‘gt’,1),array(‘lt’,10));(id > 1) AND (id < 10)
oror$where[‘id’] = array(array(‘gt’,3),array(‘lt’,10), ‘or’);(id > 3) OR (id < 10)
xor(异或)xor两个输入中只有一个是true时,结果为true,否则为false,例子略。1 xor 1 = 0
exp综合表达式$where[‘id’] = array(‘exp’,‘in(1,3,8)’);$where[‘id’] = array(‘in’,‘1,3,8’);

除此之外还有多个字段的联合查询

TP运算SQL运算说明
$where[‘user1&user2&user3’] = [‘eq’, ‘openid’];“user1= openid and user2= openid and user3= openid”多个字段相同值的and查询
$where[‘user1|user2|user3’] = [‘eq’, ‘openid’];“user1= openid or user2= openid or user3= openid”多个字段相同值的或查询
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值