thinkphp的增刪改查語句

來源:互聯網
上載者:User
<?php// 本類由系統自動產生,僅供測試用途class IndexAction extends Action{    public function index(){$user=M('user');//select  欄位 from 表where 循序關聯性不能打亂//$list=$user->field('id,username')->where('id>1')->limit('3')->order('id desc')->select();//$list=$user->select(array('where'=>'id>1','limit'=>'3','order'=>'id desc','field'=>'id,username'));//$list=$user->field('user.id as uid,message.id as mid')->table('think_user user,think_user_message message')->where('user.id=message.id')->select();//$list=$user->order(array('id'=>'desc','username'))->table(array('think_user'=>'user','think_user_message'=>'message'))->where('user.id=message.id')->select();//$user->data() 方法可以被代替,主要用在save()還有add的時候,還有delete的時候,進行使用,主要向對象中帶數//$user->group();        //$user->having();        //$user->jioin();        //distinct(true);relation();lock(true);//$list=$user->where('id=1')->getField('id,password');//更新資料//採用的是save方法非update,可以不寫where,但是對應的數組中必須有指定的條件,沒有條件會出錯//data()函數在此可以使用;save返回的是受影響的行數//$list=$user->save(array('username'=>'ljf','id'=>4));//$list=$user->data(array('username'=>'jianfe','id'=>4))->save();//返回的是增加一條記錄後的id//$list=$user->data(array('username'=>'hezhi','password'=>'33333'))->add();//可以直接傳入id//$list=$user->delete(4);//setField();setInc() 加上參數;setDec() 減上參數;//第一處寫欄位,第二處寫where條件,第三項,寫上對應的需要增加或者減少的整型(預設為1)//$list=$user->setInc('price','id=1',1);//$list=$user->where('id=1')->setField(array('username','password'),array('google','ljfbest'));//dump($list);//find();//只尋找一條記錄,返回一維數組//select();//所有資訊讀出來//findAll();//同select//$this->display();}}?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.