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

巴扎黑
Libérer: 2016-11-08 10:19:34
original
964 Les gens l'ont consulté

对于那些要实现模糊判断的查询,比如大于、等于、小于之类的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` ="蜡笔小新") )


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!