Laravel框架查詢構(gòu)造器簡單示例
本文實例講述了Laravel框架查詢構(gòu)造器。分享給大家供大家參考,具體如下:
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作為下標(biāo)
//$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相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。
- laravel技巧之查詢構(gòu)造器Query Builder疊加鏈?zhǔn)秸{(diào)用的方法
- 使用Laravel中的查詢構(gòu)造器實現(xiàn)增刪改查功能
- 解決laravel查詢構(gòu)造器中的別名問題
- Laravel框架查詢構(gòu)造器 CURD操作示例
- Laravel 使用查詢構(gòu)造器配合原生sql語句查詢的例子
- Laravel5中實現(xiàn)模糊匹配加多條件查詢功能的方法
- 在Laravel5.6中使用Swoole的協(xié)程數(shù)據(jù)庫查詢
- laravel實現(xiàn)查詢最后執(zhí)行的一條sql語句的方法
- Laravel Eloquent ORM 實現(xiàn)查詢表中指定的字段
- Laravel框架查詢構(gòu)造器常見用法總結(jié)
相關(guān)文章
ThinkPHP中html:list標(biāo)簽用法分析
這篇文章主要介紹了ThinkPHP中html:list標(biāo)簽用法,較為詳細(xì)的分析總結(jié)了ThinkPHP中html:list標(biāo)簽的定義、使用方法及相關(guān)注意事項,需要的朋友可以參考下2016-01-01
Yii2結(jié)合Workerman的websocket示例詳解
這篇文章主要給大家介紹了關(guān)于Yii2結(jié)合Workerman的websocket的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09
laravel 5 實現(xiàn)模板主題功能(續(xù))
前面一篇文章,我們簡單討論了laravel模板主題功能,本文我們繼續(xù)探討laravel模板主題功能的實現(xiàn),本次實現(xiàn)比較重,有興趣慢慢看吧。2015-03-03
關(guān)于Laravel Route重定向的一個注意點
這篇文章主要給大家介紹了關(guān)于Laravel Route重定向的一個注意點,文中給出了詳細(xì)的示例代碼,有需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01

