thinkPHP SQL语句中表达式查询的格式

巴扎黑
Freigeben: 2016-11-08 10:19:34
Original
964 Leute haben es durchsucht

对于那些要实现模糊判断的查询,比如大于、等于、小于之类的SQL查询,可以使用表达式查询方式。
查询表达式格式:$map['字段名'] = array('表达式','查询条件');

7870.tmp.jpg

PS:表达式不区分大小写。

例子:
//EQ:等于(=)
$map['id'] = array('eq', 1); //where 为id=1
//NEQ:不等于()
$map['id'] = array('neq', 1); //where 为id1
//GT:大于(>)
$map['id'] = array('gt', 1); //where 为id>1
//EGT:大于等于(>=)
$map['id'] = array('egt', 1); //where 为id>=1
//LT:小于($map['id'] = array('lt', 1); //where 为id//ELT:小于等于($map['id'] = array('elt', 1); //where 为id//[NOT]LIKE:模糊查询
$map['user'] = array('like', '%小%'); //where 为like %小%
//[NOT]LIKE:模糊查询
$map['user'] = array('notlike', '%小%'); //where 为not like %小%
//[NOT]LIKE:模糊查询的数组方式
$map['user'] = array('like', array('%小%', '%蜡%'), 'AND');
//生成的SQL
SELECT * FROM `think_user` WHERE ( (`user` LIKE '%小%' AND `user`
LIKE '%蜡%') )
//[NOT] BETWEEN:区间查询
$map['id'] = array('between','1,3');
//where 为`id` BETWEEN '1' AND '2'
//同上等效
$map['id'] = array('between',array('1','3'));
//[NOT] BETWEEN:区间查询
$map['id'] = array('not between','1,3');
//where 为`id` NOT BETWEEN '1' AND '2'
//[NOT] IN:区间查询
$map['id'] = array('in','1,2,4');
//where 为`id` IN ('1','2','4')
//[NOT] IN:区间查询
$map['id'] = array('not in','1,2,4');
//where 为`id` NOT IN ('1','2','4')
//EXP:自定义
$map['id'] = array('exp','in (1,2,4)');
//where 为`id` NOT IN ('1','2','4')
PS:使用exp 自定义在第二个参数直接写where 语句即可
//EXP:自定义增加OR 语句
$map['id'] = array('exp', '=1');
$map['user'] = array('exp', '="蜡笔小新"');
$map['_logic'] = 'OR';
//WHERE 为( (`id` =1) ) OR ( (`user` ="蜡笔小新") )


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!