码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp 数据访问

时间:2016-12-22 14:39:46      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:set   thinkphp   select   having   date   esc   商城   技术   think   

技术分享


<?php namespace Admin\Controller; use Think\Controller; class MainController extends Controller { public function showList() { echo "大苹果商城"; } public function test() { //数据访问 //造模型对象 $nation = D("Nation"); //查询 //$a = $nation->select(); //查所有,返回关联数组 //$a = $nation->select("n001,n002,n003"); //通过主键查 //$a = $nation->find("n002"); //查一条数据 连贯操作 $a = $nation->where("name=‘汉族‘ or name=‘回族‘")->select(); //加条件 $a = $nation->table("Info")->select(); //切换表 $a = $nation->field("name")->select(); //查询指定字段
技术分享
$a = $nation->order("code desc")->select(); //排序 $a = $nation->limit(3,3)->select(); //分页 $a = $nation->page(3,3)->select(); //分页 $a = $nation->table("Car")->field("Brand,avg(Price)")->group("Brand")->select(); //分组 $a = $nation->table("Car")->field("Brand,avg(Price)")->group("Brand")->having("avg(Price)>50")->select(); $a = $nation->alias(‘a‘)->field("b.Code as ‘code‘,b.Name as ‘name‘,a.name as ‘民族‘")->join("Info b on a.Code=b.Nation")->select(); $a = $nation->table("car")->distinct(true)->field("brand")->select(); $a = $nation->where("code=‘n003‘")->getField("name"); //获取某一列的值 $a = $nation->table("car")->sum(Price); var_dump($a); //$sql = "update nation set name=‘矮人族‘ where code=‘n001‘"; //$a = $nation->query($sql); //执行查询 //$a = $nation->execute($sql); //执行其他操作 //var_dump($a); } }

 

thinkphp 数据访问

标签:set   thinkphp   select   having   date   esc   商城   技术   think   

原文地址:http://www.cnblogs.com/benpaodegegen/p/6210654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!