ThinkPHP运算符 与 SQL运算符 对比表
2016-01-17 11:49
573 查看
ThinkPHP运算符 与 SQL运算符 对比表 | |||
TP运算符 | SQL运算符 | 样例 | 实际查询条件 |
eq | = | $map['id'] = array('eq',100); | 等效于:$map['id'] = 100; |
neq | != | $map['id'] = array('neq',100); | id != 100 |
gt | > | $map['id'] = array('gt',100); | id > 100 |
egt | >= | $map['id'] = array('egt',100); | id >= 100 |
lt | < | $map['id'] = array('lt',100); | id < 100 |
elt | <= | $map['id'] = array('elt',100); | id <= 100 |
like | like | $map<'username'> = array('like','Admin%'); | username like 'Admin%' |
between | between and | $map['id'] = array('between','1,8'); | id BETWEEN 1 AND 8 |
not between | not between and | $map['id'] = array('not between','1,8'); | id NOT BETWEEN 1 AND 8 |
in | in | $map['id'] = array('in','1,5,8'); | id in(1,5,8) |
not in | not in | $map['id'] = array('not in','1,5,8'); | id not in(1,5,8) |
and(默认) | and | $map['id'] = array(array('gt',1),array('lt',10)); | (id > 1) AND (id < 10) |
or | or | $map['id'] = array(array('gt',3),array('lt',10), 'or'); | (id > 3) OR (id < 10) |
xor(异或) | xor | 两个输入中仅仅有一个是true时。结果为true,否则为false,样例略。 | 1 xor 1 = 0 |
exp | 综合表达式 | $map['id'] = array('exp','in(1,3,8)'); | $map['id'] = array('in','1,3,8'); |
or | 不同字段 or | $map['id'] = '8'; $map['pid'] = '10'; $map['_logic'] = 'OR'; | 'id'=8 AND 'pid'=10 |
补充说明
· 同 SQL 一样,ThinkPHP运算符不区分大写和小写。eq 与 EQ 一样。· between、 in 条件支持字符串或者数组,即以下两种写法是等效的:
$map['id'] = array('not in','1,5,8');
$map['id'] = array('not in',array('1','5','8'));
·
exp 表达式
上表中的 exp 不是一个运算符。而是一个综合表达式以支持更复杂的条件设置。exp 的操作条件不会被当成字符串。能够使用不论什么 SQL 支持的语法。包含使用函数和字段名称。
exp 不仅用于 where 条件,也能够用于数据更新,如:
$Dao = M("Article");
// 构建 save 的数据数组,文章PV数+1
$data['id'] = 10;$data['counter'] = array('exp','counter+1');
// 依据条件保存改动的数据
$User->save($data);
ThinkPHP Where 条件中使用表达式
原文出自: /article/5001573.html相关文章推荐
- zend studio 一直试用的方法
- Zend Studio左边的工具栏被隐藏了怎么恢复?
- php 引用和global
- 数据库--PHP环境搭建
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- 欢迎使用CSDN-markdown编辑器
- 关于Zend studi使用的一些技巧(zendstudio自动换行,zendstudio汉化)
- zend studio 10 字体,颜色,快捷键等相关设置
- 解决ZendStudio打开utf-8格式的php文件乱码
- php环境搭建
- Zend Studio12的安装破解注册教程
- Yii2开启简单地址访问
- PHP学习笔记——从搭建PHP开发环境开始
- EditPlus注册码在线生成,删除utf-8BOM,完美解决php文件乱码问题
- mysql 数据查询时 中文乱码问题 以 php 为例
- 【php】 勾搭 Composer\Autoload\ClassLoader 类
- ThinkPHP_MVC
- 触摸屏TP基础学习笔记资料整理
- Could not connect to SMTP host: smtp.***.com, port: 465, response: -1
- PHP慢脚本日志和Mysql的慢查询日志