Table of Contents
thinkPHP查询方式小结,thinkphp查询方式
您可能感兴趣的文章:
Home php教程 php手册 thinkPHP查询方式小结,thinkphp查询方式

thinkPHP查询方式小结,thinkphp查询方式

Jun 13, 2016 am 08:47 AM
sql statement thinkphp Inquire

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

Copy after login

二、表达式查询

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,

Copy after login

三、区间查询

$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

四、统计查询

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用于对数据进行写入

Copy after login

更多关于thinkPHP相关内容可查看本站专题:《ThinkPHP入门教程》及《ThinkPHP常用方法总结》

希望本文所述对大家基于thinkPHP框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • ThinkPHP中关联查询实例
  • ThinkPHP采用原生query实现关联查询left join实例
  • thinkphp数据查询和遍历数组实例
  • thinkphp普通查询与表达式查询实例分析
  • ThinkPHP查询语句与关联查询用法实例
  • thinkphp实现like模糊查询实例
  • ThinkPHP查询返回简单字段数组的方法
  • ThinkPHP中的常用查询语言汇总
  • thinkphp学习笔记之多表查询
  • ThinkPHP视图查询详解
  • ThinkPHP多表联合查询的常用方法
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? ThinkPHP6 routing: How to completely obtain URL parameters containing special characters such as Chinese? Apr 01, 2025 pm 02:51 PM

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...

How to query the sum of two columns of data at the same time in ThinkPHP6? How to query the sum of two columns of data at the same time in ThinkPHP6? Apr 01, 2025 pm 02:54 PM

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? Comparison of Redis queues and MySQL stability: Why is Redis prone to data loss? Apr 01, 2025 pm 02:24 PM

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 sort the product list by dragging and ensure that the spread is effective? How to sort the product list by dragging and ensure that the spread is effective? Apr 02, 2025 pm 01:00 PM

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 and support spreading operations by dragging? How to sort the product list and support spreading operations by dragging? Apr 02, 2025 pm 01:12 PM

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 Element uploads large files online errors: How to troubleshoot cross-domain problems and other potential causes? Vue Element uploads large files online errors: How to troubleshoot cross-domain problems and other potential causes? Apr 01, 2025 pm 12:48 PM

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

distinct multiple fields usage distinct multiple fields usage Apr 03, 2025 pm 10:21 PM

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.

Why do the results of ORDER BY statements in SQL sorting sometimes seem random? Why do the results of ORDER BY statements in SQL sorting sometimes seem random? Apr 02, 2025 pm 05:24 PM

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"...

See all articles