ThinkPHP like fuzzy query like multi match query between query in query general query writing method

  • 2021-11-01 23:50:00
  • OfStack

ThinkPHP database condition query statement has string type, array type writing method

String type is the original type, array type query statement because of the writing style and the specific character reason is more complex, the following example for everyone in common use of ThinkPHP array type query statement

ThinkPHP1-like query

$data_gt['id']=array('gt',8);//gt:>大于
$data_egt['id']=array('egt',8);//egt:>=大于等于
$data_lt['id']=array('lt',8);//lt:<小于
$data_elt['id']=array('elt',8);//elt:<=小于等于
$data_eq['id']=array('eq',8);//eq:=等于
$data_neq['id']=array('neq',8);//eq:!=不等于

ThinkPHP like Fuzzy Query

$data_like['username']=array('like','%A%');//包含A的所有username
$data_like['username']=array('like','%A%');//包含A的所有username
$data_notlike['username']=array('notlike','%A%');//不包含A的所有username,注意notlike中间没有空格

ThinkPHP like Multiple Matching Query

All username that contain A or 2. If there is no third parameter in the array, the default is or

$data_like_mul_or['username']=array('like',array('%A%','%2%'));

All username that contain A and 2, add a third parameter to the array, and, if the relationship between and is required

$data_egt['id']=array('egt',8);//egt:>=大于等于0

ThinkPHP Between Interval Query

Query the records of id between 6 and 13 (including the values at both ends)

$data_between['id']=array('between',array(6,13));

Query records where id is not between 6 and 13 (excluding values at both ends). Note that there must be a space between not and between in 1

$data_not_between['id']=array('not between',array(6,13));

ThinkPHP In Interval Query

Query the records of id in this array

$data_in['id']=array('in',array(6,7,8,9,10));

Query for records where id is not in this array. Note that spaces are also used between not and in

$data_not_in['id']=array('not in',array(6,7,8,9,10));

ThinkPHP Multi-field Same Query

$data_like['title|username']=array('like',"%{$key}%");

ThinkPHP Multi-field Different Query

$data['status&score&title'] =array('1',array('gt','0'),'thinkphp','_multi'=>true);

'_multi'= > true must be added at the end of the array to indicate that there is a multi-condition match, so the query condition becomes status = 1 AND title = 'thinkphp'

These are the basic writing methods of ThinkPHP array query statement. Please see the following related articles for more usage methods


Related articles: