Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the where () method of thinkphp

Shulou Source: shulou.com Published: 2022-06-02 07:16:00 10月04日 Update

This article mainly explains "how to use the where() method of thinkphp". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "how to use the where() method of thinkphp" together!

The usage of where method is the essence of ThinkPHP query language, and it is also an important part and highlight of ThinkPHP ORM. It can complete query operations including ordinary query, expression query, shortcut query, interval query and combination query. The where method supports strings and arrays as arguments, although objects can be used but are not recommended.

string condition $User = M("User"); //instantiate User object $User->where ('type =1 AND status= 1')->select();

SELECT * FROM think_user WHERE type=1 AND status=1

array condition ordinary query $User = M("User"); //instantiate User object $map <$'name ']='thinkphp';$map <$'status '] = 1; //pass query condition to query method $User->where($map)->select();

SELECT * FROM think_user WHERE `name`='thinkphp' AND status=1

expression query $map <$'field 1'] = array ('expression','query condition1');$map <$'field 2'] = array ('expression','query condition2');$Model->where($map)->select(); //$map <$'id '] = array ('eq', 100) is also supported;

The query condition represented is id = 100

$map['id'] = array('neq',100);

The query condition represented is id 100

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

The query condition represented is id > 100

$map['id'] = array('egt',100);

The query condition represented is id >= 100

$map['id'] = array('lt',100);

The query condition represented is id

< 100 $map['id'] = array('elt',100); 表示的查询条件就是 id where($map)->

select();

The final query condition is: ( `id` != 1 ) AND ( `name` = 'ok' ) AND ( status=1 AND score>10 )

composed query

$where['name'] = array('like', '%thinkphp%');$where['title'] = array('like','%thinkphp%');$where['_logic'] = 'or';$map['_complex'] = $where;$map['id'] = array('gt',1);

equivalent to

$where['id'] = array('gt',1);$where['_string'] = ' (name like "%thinkphp%") OR ( title like "%thinkphp") ';

query condition

( id > 1) AND ( ( name like '%thinkphp%') OR ( title like '%thinkphp%') )

These are common where query methods.

Thank you for reading, the above is the content of "how to use the where() method of thinkphp". After studying this article, I believe that everyone has a deeper understanding of how to use the where() method of thinkphp. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Query condition method that is expression support character string object array instance learning normal content field situation combination complex important bright spot Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple macOS Shulou Tech Info Linux