ThinkPHP查询语言之复合查询:修订间差异
来自站长百科
(新页面: <span style="border:1px solid #000; float:right; text-align:center; padding:6px;"><strong>导航:</strong>上一页</span> <div style="cle...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
<span style="border:1px solid #000; float:right; text-align:center; padding:6px;"><strong>导航:</strong>[[ThinkPHP开发指南-模型之查询语言|上一页]]</span> | <span style="border:1px solid #000; float:right; text-align:center; padding:6px;"><strong>导航:</strong>[[ThinkPHP开发指南-模型之查询语言|上一页]]</span> | ||
<div style="clear:both;"></div> | <div style="clear:both;"></div> | ||
新版完善了复合查询,可以完成比较复杂的查询条件组装。例如: | |||
'''PHP代码''' | |||
<pre> | |||
$where['name'] = array('like', '%thinkphp%'); | |||
$where['title'] = array('like', '%thinkphp%'); | |||
$where['_logic'] = 'or'; | |||
$map['_complex'] = $where; | |||
$map['id'] = array('gt',1); | |||
</pre> | |||
查询条件是 | |||
'''PHP代码''' | |||
<pre> | |||
( id > 1) AND ( ( name like '%thinkphp%') OR ( title like '%thinkphp%') ) | |||
</pre> | |||
'''复合查询'''使用了_complex作为子查询条件来定义,配合之前的查询方式,可以非常灵活的制定更加复杂的查询条件. 相同的查询条件有多种表达形式,例如上面的查询条件可以改成: | |||
'''PHP代码''' | |||
<pre> | |||
$where['id'] = array('gt',1); | |||
$where['_string'] = ' (name like "%thinkphp%") OR ( title like "%thinkphp") '; | |||
</pre> | |||
最后生成的[[SQL]]语句是一致的。 | |||
[[category:ThinkPHP]] |
2010年5月10日 (一) 14:32的最新版本
导航:上一页
新版完善了复合查询,可以完成比较复杂的查询条件组装。例如:
PHP代码
$where['name'] = array('like', '%thinkphp%'); $where['title'] = array('like', '%thinkphp%'); $where['_logic'] = 'or'; $map['_complex'] = $where; $map['id'] = array('gt',1);
查询条件是
PHP代码
( id > 1) AND ( ( name like '%thinkphp%') OR ( title like '%thinkphp%') )
复合查询使用了_complex作为子查询条件来定义,配合之前的查询方式,可以非常灵活的制定更加复杂的查询条件. 相同的查询条件有多种表达形式,例如上面的查询条件可以改成:
PHP代码
$where['id'] = array('gt',1); $where['_string'] = ' (name like "%thinkphp%") OR ( title like "%thinkphp") ';
最后生成的SQL语句是一致的。