基于laravel5.4版本的查询构造器的简单几个操作:(相对于TP3.2版本)
//获取指定多行多列,二维,,对象 【select】 $names = ‘‘; $names = DB::table(‘student‘)->whereRaw(‘id > ? and age < ?‘,[1,100])->select(‘id‘,‘name‘,‘age‘)->get(); var_dump($names); echo "<br>"; //获取指定单行,一维,,对象 【find】 $names = ‘‘; $names = DB::table(‘student‘)->whereRaw(‘id > ? and age < ?‘,[1,100])->select(‘id‘,‘name‘,‘age‘)->first(); var_dump($names); echo "ceshi"; echo "<br>"; //获取指定列值,返回字符串【getField】 $names = DB::table(‘student‘)->whereRaw(‘id >= ? and age < ?‘,[1,100])->value(‘name‘); var_dump($names); // string(3) "bob" echo "<br>"; //获取指定name单列,返回一维数组【getField,true】 $names = ‘‘; $names = DB::table(‘student‘)->whereRaw(‘id >= ? and age < ?‘,[1,100])->pluck(‘name‘); var_dump($names); echo "<br>"; var_dump(json_encode($names,true));// array "["Alice"]"
以后再添加难的和其他的。