thinkphp 資料訪問

來源:互聯網
上載者:User

標籤:set   thinkphp   select   having   date   esc   商城   技術   think   



<?phpnamespace 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 資料訪問

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.