A simple example of query builder for laravel framework


An example of this article describes the laravel framework query builder. To share with you for your reference, as follows:

public function query(){
  //New data
  //$bool = DB::table('wd_user')->insert(['username'=>'jack']);
  //New data并且获取到自增id
  //$id = DB::table('wd_user')->insertGetid(['username'=>'Tom']);
  //Add multiple data
  //$bool = DB::table('wd_user')->insert([['username'=>'a'],['username'=>'d']]);
  //Update data
  //$bool = DB::table('wd_user')->where('uid',7)->update(['username'=>'tom']);
  // self increment
  //$bool = DB::table('wd_user')->increment('age',1);
  // self decreasing
  //$bool = DB::table('wd_user')->decrement('age',1);
  // self decreasing并且更新数据
  //$bool = DB::table('wd_user')->decrement('age',1,['name'=>'imooc']);
  //Delete data
  //$bool = DB::table('wd_user')->where('uid','>=',7)->delete();
  // empty list
  //Get data
  //$user = DB::table('wd_user')->get();
  //Data sorting
  //$user = DB::table('wd_user')->orderBy('uid','desc')->get();
  //Add query criteria
  //$user = DB::table('wd_user')->where('uid','>=',5)->get();
  //Add multiple query criteria
  //$user = DB::table('wd_user')->where('uid > ? and age > ?',[5,18])->get();
  //Query specified fields
  //$user = DB::table('wd_user')->pluck('username');
  //Query the specified field with uid as the subscript
  //$user = DB::table('wd_user')->lists('username','uid');
  //Query some fields specified
  //$user = DB::table('wd_user')->select('uid','username')->get();
  //Segment query data
  //Count the number of records
  //$num = DB::table('wd_user')->count();
  //Query Max
  //$max = DB::table('wd_user')->max();
  //Query minimum
  //$min = DB::table('wd_user')->min();
  //Query average
  //$avg = DB::table('wd_user')->avg();
  //Statistics and values
  //$sum = DB::table('wd_user')->sum();

For more information about laravel, readers who are interested in the content can see the special topics of this site: introduction and advanced course of laravel framework, summary of PHP excellent development framework, introduction course of PHP object-oriented programming, introduction course of PHP + MySQL database operation and summary of PHP common database operation skills

I hope that this article will be helpful for you to Design PHP program based on laravel framework.