thinkPHP查询方式小结,thinkphp查询方式
thinkPHP查询方式小结,thinkphp查询方式
本文实例总结了thinkPHP查询方式。分享给大家供大家参考,具体如下:
一、普通查询方式
1. 使用字符串查询;
复制代码 代码如下:$m->where(' id=1 and name="roge" ')->find();
这种方法存在一个缺点,就是当数据表中的查询字段为字符串时,需要在字段值中加入引号。
2. 使用数组的方式(推荐使用)
$data['name']="adfa"; $data['id']=3; $data['_logic']="or"; //字段之间的逻辑关系,默认为and的关系 $m->where($data)->find();
二、表达式查询
EQ 等于;
NEQ 不等于;
GT 大于;
EGT 大于等于;
LT 小于;
ELT 小于等于;
LIKE 模糊查询;
$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,
三、区间查询
$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();
四、统计查询
count,max, min, avg, sum
复制代码 代码如下:$m->max('id')
五、SQL直接查询
$m=M(); $result=$m->query("select * from think_user where id>1") //query主要用于对数据进行读取 $result=$m->execute("insert into think_user(`name`) values ('dfd') "); //execute用于对数据进行写入
更多关于thinkPHP相关内容可查看本站专题:《ThinkPHP入门教程》及《ThinkPHP常用方法总结》
希望本文所述对大家基于thinkPHP框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
- ThinkPHP中关联查询实例
- ThinkPHP采用原生query实现关联查询left join实例
- thinkphp数据查询和遍历数组实例
- thinkphp普通查询与表达式查询实例分析
- ThinkPHP查询语句与关联查询用法实例
- thinkphp实现like模糊查询实例
- ThinkPHP查询返回简单字段数组的方法
- ThinkPHP中的常用查询语言汇总
- thinkphp学习笔记之多表查询
- ThinkPHP视图查询详解
- ThinkPHP多表联合查询的常用方法

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



ThinkPHP6 routing parameters are processed in Chinese and complete acquisition. In the ThinkPHP6 framework, URL parameters containing special characters (such as Chinese and punctuation marks) are often processed...

ThinkPHP6 database query: How to use TP6 to implement SQL statements SELECTSUM(jin), SUM(chu)FROMsysdbuil In ThinkPHP6 framework, how to use SQL statement SELECT...

Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? In the development environment, using PHP7.2 and ThinkPHP frameworks, we often face the choice of cooperation...

How to implement product list sorting by dragging. When dealing with front-end product list sorting, we face an interesting need: users do it by dragging products...

How to sort the product list by dragging? When dealing with e-commerce platforms or similar applications, you often encounter the need to sort the product list...

Vue Elementel-upload upload file online error reporting and troubleshooting using Vue and Element...

distinct can deduplicate data for multiple fields, and only if the values of all specified fields are exactly the same, keeping a unique row. When using distinct, you need to pay attention to the deduplication according to the specified field combination and cannot be deduplication based on some fields. Additionally, for large tables, using distinct may affect performance, and it is recommended to index or pre-calculate the results to optimize query speed.

Confused about the sorting of SQL query results. In the process of learning SQL, you often encounter some confusing problems. Recently, the author is reading "MICK-SQL Basics"...
