search
Homephp教程php手册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多表联合查询的常用方法
Statement
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools