Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the where () method of thinkphp

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report