您的位置:首页 > 编程语言 > PHP开发

[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是传入的值)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: