[PHP][TP]数据库查询语句
2015-12-25 20:55
579 查看
//1.直接用字符串进行查询
$data=M(‘User’)->where(‘id=1’)->select();
//2.使用数组方式进行查询
where[‘username′]=”xiaoming”;//查询条件where[‘user_name’]=”xiaoming”;//查询条件
where[‘_logic’]=’or’;//查询方式
//3. 表达式查询
//eq(=) neq(!=) egt(>=) gt(>) lt(<) elt(<=)
//like(like) between (between and) not between(not between and) in (in) not in (not in) and(and[默认])
//where[‘字段名′]=array(‘表达式′,查询条件);//where[‘字段名’]=array(‘表达式’,查询条件);
//where [‘id’]=array(‘lt’,3);//查询<3的数据
where[‘id′]=array(‘between′,′1,8′);//查询id是1到8的数据where[‘id’]=array(‘between’,’1,8’);//查询id是1到8的数据
where[‘id’]=array(‘lt’3);//查询id<3的数据
$where[‘user_name’]=array(‘like’,array(‘%ming’,’xiao%’));//查询user_name模糊等于%ming 模糊等于xiao的数据
//4.区间查询
where[‘id’]=array(array(‘gt’,100),array(‘lt’,3),’or’);//查询>100 或者<3的数据
//5.混合查询
where[‘id′]=array(‘gt′10);//查询id>10的数据where[‘id’]=array(‘gt’ 10);//查询id>10的数据
where[‘_string’]=’scoer>10’;// 查询scoer>10的数据
//6.统计用法
// count统计数量 可选
// max 获取最大值 必须传入 统计的字段名
// min 获取最小值 必须传入 统计的字段名
// avg 平均值 必须传入 统计的字段名
// sum 求和 必须传入 统计的字段名
$data =M(‘user’)->min(‘id’);//查询语句(其中id是传入的值)
$data=M(‘User’)->where(‘id=1’)->select();
//2.使用数组方式进行查询
where[‘username′]=”xiaoming”;//查询条件where[‘user_name’]=”xiaoming”;//查询条件
where[‘_logic’]=’or’;//查询方式
//3. 表达式查询
//eq(=) neq(!=) egt(>=) gt(>) lt(<) elt(<=)
//like(like) between (between and) not between(not between and) in (in) not in (not in) and(and[默认])
//where[‘字段名′]=array(‘表达式′,查询条件);//where[‘字段名’]=array(‘表达式’,查询条件);
//where [‘id’]=array(‘lt’,3);//查询<3的数据
where[‘id′]=array(‘between′,′1,8′);//查询id是1到8的数据where[‘id’]=array(‘between’,’1,8’);//查询id是1到8的数据
where[‘id’]=array(‘lt’3);//查询id<3的数据
$where[‘user_name’]=array(‘like’,array(‘%ming’,’xiao%’));//查询user_name模糊等于%ming 模糊等于xiao的数据
//4.区间查询
where[‘id’]=array(array(‘gt’,100),array(‘lt’,3),’or’);//查询>100 或者<3的数据
//5.混合查询
where[‘id′]=array(‘gt′10);//查询id>10的数据where[‘id’]=array(‘gt’ 10);//查询id>10的数据
where[‘_string’]=’scoer>10’;// 查询scoer>10的数据
//6.统计用法
// count统计数量 可选
// max 获取最大值 必须传入 统计的字段名
// min 获取最小值 必须传入 统计的字段名
// avg 平均值 必须传入 统计的字段名
// sum 求和 必须传入 统计的字段名
$data =M(‘user’)->min(‘id’);//查询语句(其中id是传入的值)
相关文章推荐
- php 赋值原理详解
- phpstorm 快捷键
- php解析html类
- mysql php使用
- php官方文档学习 w3c
- PHP(七)数组
- Jmeter FTP test
- IIS创建ftp服务器和ftp上传发布项目的步骤
- zabbix报PHP gettext extension missing
- PHP 教程
- php 常用函数
- 解析提高PHP执行效率的50个技巧
- 安装xcache3.0.3/3.2,为php加速
- 安装xcache3.0.3/3.2,为php加速
- PHP - 魔术方法
- 黄聪:PHP使用Simple_HTML_DOM遍历、过滤及保留指定属性
- Laravel中的日志与上传
- php【基础学习八】URL编解码
- php【基础学习七】string操作
- MSTP+VRRP组合实现S1和S2的(双交换)热备冗余及负载均衡