主頁 > 知識庫 > Laravel框架查詢構(gòu)造器簡單示例

Laravel框架查詢構(gòu)造器簡單示例

熱門標簽:阿里云 科大訊飛語音識別系統(tǒng) 銀行業(yè)務(wù) 團購網(wǎng)站 Mysql連接數(shù)設(shè)置 服務(wù)器配置 Linux服務(wù)器 電子圍欄

本文實例講述了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作為下標
  //$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疊加鏈式調(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é)

標簽:棗莊 廣元 大理 蚌埠 衢州 萍鄉(xiāng) 江蘇 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Laravel框架查詢構(gòu)造器簡單示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266