Summary of thinkPHP query methods, thinkphp query methods_PHP tutorial

WBOY
Release: 2016-07-12 09:01:12
Original
931 people have browsed it

Summary of thinkPHP query methods, thinkphp query methods

The examples in this article summarize the thinkPHP query methods. Share it with everyone for your reference, the details are as follows:

1. Common query methods

1. Use string query;
Copy code The code is as follows: $m->where(' id=1 and name="roge" ')->find();
One disadvantage of this method is that when the query field in the data table is a string, quotation marks need to be added to the field value.

2. Using arrays (recommended)

$data['name']="adfa";
$data['id']=3;
$data['_logic']="or"; //字段之间的逻辑关系,默认为and的关系
$m->where($data)->find();

Copy after login

2. Expression query

EQ is equal to;
NEQ is not equal;
GT Greater than;
EGT is greater than or equal to;
LT is less than;
ELT 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,

Copy after login

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();

Copy after login

4. Statistical query

count, max, min, avg, sum
Copy code The code is as follows: $m->max('id')
5. SQL direct query

$m=M();
$result=$m->query("select * from think_user where id>1")
//query主要用于对数据进行读取
$result=$m->execute("insert into think_user(`name`) values ('dfd') ");
//execute用于对数据进行写入

Copy after login

For more information related to thinkPHP, please view the special topics on this site: "Introduction to ThinkPHP Tutorial" and "Summary of Common Methods of ThinkPHP"

I hope this article will be helpful to everyone’s PHP programming based on the thinkPHP framework.

Articles you may be interested in:

  • Example of associated query in ThinkPHP
  • ThinkPHP uses native query to implement associated query left join example
  • thinkphp data query and Traversing array examples
  • Thinkphp common query and expression query example analysis
  • ThinkPHP query statement and related query usage examples
  • thinkphp implements like fuzzy query examples
  • The method of ThinkPHP query to return a simple field array
  • A summary of common query languages ​​in ThinkPHP
  • thinkphp study notes multi-table query
  • Detailed explanation of ThinkPHP view query
  • Common methods for joint query of multiple tables in ThinkPHP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1089930.htmlTechArticleSummary of thinkPHP query method, thinkphp query method This article summarizes thinkPHP query method through examples. Share it with everyone for your reference, the details are as follows: 1. Common query methods 1. Use the characters...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!