The examples in this article summarize the thinkPHP query method. Share it with everyone for your reference, the details are as follows:
1. Ordinary query method
1. Use string query;
Copy the code The code is as follows:
$m->where(' id=1 and name="roge" ')->find();
2. Using arrays (recommended)
$data['name']="adfa"; $data['id']=3; $data['_logic']="or"; //字段之间的逻辑关系,默认为and的关系 $m->where($data)->find();
2. Expression query
EQ is equal to;
NEQ is not equal to;
GT is greater than;
EGT is greater than or equal to;
LT is less than;
ELT is less than or equal to;
LIKE Fuzzy query;
$data['id']=array('gt',6); $data['name']=array('like','%as%'); //notlike //$data['name']=array('like',array('%as%','%ts'),'and'); 默认为or关系,如果用and需要明确指定 $m->where($data)->select(); //其他查询 between, not between (之间有空格),in,not between,
3. Interval query
$data['id']=array(array('gt',5),array('lt',10)); //默认生成的是and的关系 //$data['id']=array(array('lt',5),array('gt',10),'or') $data['name']=array(array('like','%d%'),array('like','%e%'),'gege','or'); $m->where($data)->select();
4. Statistical query
count, max, min, avg, sum
Copy code The code is as follows:
$m- >max('id')
$m=M(); $result=$m->query("select * from think_user where id>1") //query主要用于对数据进行读取 $result=$m->execute("insert into think_user(`name`) values ('dfd') "); //execute用于对数据进行写入
For more information related to thinkPHP, please check out the special topics on this site: "ThinkPHP Getting Started Tutorial" and "Summary of Common Methods of ThinkPHP"
I hope this article will explain It will be helpful for everyone to design PHP programs based on the thinkPHP framework.
The above is a summary of thinkPHP query methods, including relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.