1. 程式人生 > >tp 3.2 組合查詢, 字符串模式查詢

tp 3.2 組合查詢, 字符串模式查詢

字符 str bin query cor user span like bsp

$User = M("User"); // 實例化User對象

$map[‘id‘] = array(‘neq‘,1);

$map[‘name‘] = ‘ok‘;

$map[‘_string‘] = ‘status=1 AND score>10‘;

$User->where($map)->select();

最後轉化為:

( `id` != 1 ) AND ( `name` = ‘ok‘ ) AND ( status=1 AND score>10 )

2

$map[‘id‘] = array(‘gt‘,‘100‘);

$map[‘_query‘] = ‘status=1&score=100&_logic=or‘;

轉化為:

`id`>100 AND (`status` = ‘1‘ OR `score` = ‘100‘)

3

$where[‘name‘] = array(‘like‘, ‘%thinkphp%‘);

$where[‘title‘] = array(‘like‘,‘%thinkphp%‘);

$where[‘_logic‘] = ‘or‘;

$map[‘_complex‘] = $where;

轉化為:

$map[‘id‘] = array(‘gt‘,1);( id > 1) AND ( ( name like ‘%thinkphp%‘) OR ( title like ‘%thinkphp%‘) )

來源:http://document.thinkphp.cn/manual_3_2.html#combine_query

tp 3.2 組合查詢, 字符串模式查詢