数据库模型

数据库模型的相关DB操作方法请参阅数据库模型

参数条件

数据库模型支持复杂的参数条件拼接,大多数情况下这些参数拼接条件就足以完成常用的查询需求。

简单匹配:

$u = new Model('user');
$u->where(array('name'=>'张三'));

匹配的条件为:

where name = '张三'

对比匹配:

$u = new Model('user');
$u->where(array('name'=>'张三','age@<'=>30,'age@>='=>20));

匹配的条件为:

where name = '张三' and age <30 and age >=20

相似度匹配:

$u = new Model('user');
$u->where(array('name'=>'张三','age@<'=>30,'age@>='=>20,'local1@~'=>'北京','local2@|~'=>'北','local3@~|'=>'京'));

匹配的条件为:

where name = '张三' and age <30 and age >=20 and local1 like '%北京%' and local2 like '北%' and local3 like '%京'

空匹配:

$u = new Model('user');
$u->where(array('local1@~'=>'北京','local2@|~'=>'北','local3@~|'=>'京','part'=>null,'level'=>true));

匹配的条件为:

where  local1 like '%北京%' and local2 like '北%' and local3 like '%京' and part is null and level is not null

范围匹配:

$u = new Model('user');
$u->where(array('part'=>null,'level'=>true,'height'=> array('1.5','1.6','1.7')));

匹配的条件为:

where   part is null and level is not null and (height = '1.5' or height = '1.6' or height = '1.7')

或者匹配:

$u = new Model('user');
$u->where(array('height'=> array('1.5','1.6','1.7'), 'or' => array('id'=>'2','id'=>'3')));

匹配的条件为:

where   (height = '1.5' or height = '1.6' or height = '1.7') and (id='2' or id='3')

直接或者匹配

$u = new Model('user');
$u->where(array('or' => array('id'=>'2','id'=>'3')));

匹配的条件为:

where   id='2' or id='3'

当然如果以上规则不好理解你可以使用常规方式,例如:

$u->where(" (height = ? or height = ? or height = ?) and (id=? or id=?)",array('1.5','1.6','1.7','2','3'));