這篇文章給大家介紹怎么在Laravel框架中實現(xiàn)一個查詢構(gòu)造器,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

具體如下:
public function query(){
//新增數(shù)據(jù)
//$bool = DB::table('wd_user')->insert(['username'=>'jack']);
//dd($bool);
//新增數(shù)據(jù)并且獲取到自增id
//$id = DB::table('wd_user')->insertGetid(['username'=>'Tom']);
//dd($id);
//新增多條數(shù)據(jù)
//$bool = DB::table('wd_user')->insert([['username'=>'a'],['username'=>'d']]);
//dd($bool);
//更新數(shù)據(jù)
//$bool = DB::table('wd_user')->where('uid',7)->update(['username'=>'tom']);
//dd($bool);
//自增
//$bool = DB::table('wd_user')->increment('age',1);
//自減
//$bool = DB::table('wd_user')->decrement('age',1);
//自減并且更新數(shù)據(jù)
//$bool = DB::table('wd_user')->decrement('age',1,['name'=>'imooc']);
//刪除數(shù)據(jù)
//$bool = DB::table('wd_user')->where('uid','>=',7)->delete();
//dd($bool);
//清空表
//DB::table('wd_user')->truncate();
//獲取數(shù)據(jù)
//$user = DB::table('wd_user')->get();
//dd($user);
//數(shù)據(jù)排序
//$user = DB::table('wd_user')->orderBy('uid','desc')->get();
//dd($user);
//增加查詢條件
//$user = DB::table('wd_user')->where('uid','>=',5)->get();
//dd($user);
//增加多個查詢條件
//$user = DB::table('wd_user')->where('uid > ? and age > ?',[5,18])->get();
//dd($user);
//查詢指定的字段
//$user = DB::table('wd_user')->pluck('username');
//dd($user);
//查詢指定字段并以uid作為下標
//$user = DB::table('wd_user')->lists('username','uid');
//dd($user);
//查詢指定的一些字段
//$user = DB::table('wd_user')->select('uid','username')->get();
//dd($user);
//分段查詢數(shù)據(jù)
//DB::table('wd_user')->chunk(2,function($user){
//var_dump($user);
//});
//統(tǒng)計記錄條數(shù)
//$num = DB::table('wd_user')->count();
//dd($num);
//查詢較大值
//$max = DB::table('wd_user')->max();
//查詢最小值
//$min = DB::table('wd_user')->min();
//查詢平均數(shù)
//$avg = DB::table('wd_user')->avg();
//統(tǒng)計和值
//$sum = DB::table('wd_user')->sum();
}關(guān)于怎么在Laravel框架中實現(xiàn)一個查詢構(gòu)造器就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
分享文章:怎么在Laravel框架中實現(xiàn)一個查詢構(gòu)造器-創(chuàng)新互聯(lián)
本文路徑:http://chinadenli.net/article6/dhceig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、網(wǎng)站維護、網(wǎng)站內(nèi)鏈、關(guān)鍵詞優(yōu)化、商城網(wǎng)站、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容