<?php
namespace App\Http\Controllers\Home;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Input;
use DB;
class IndexController extends Controller
{
//
public function index(){
$id=Input::get('id','10086');
echo '访问Home下面的index方法'.$id;
}
public function add(){
$id=Input::get('id','10086');
$db=DB::table("user");
$res=$db->insert([['name'=>12,'age'=>23,'sex'=>0],['name'=>12,'age'=>23,'sex'=>0]]);
dd($res);
$id=$db->insertGetId(['name'=>12,'age'=>23,'sex'=>0]); //单挑插入
dd($id);
}
public function del(){
$db=DB::table("user");
$result=$db->where('id','>=',3)->delete();
$result=$db->where('id','>=',3)->truncate(); //清空数据表 不受条件的影响
dd($result);
}
public function update(){
$db=DB::table("user");
$result=$db->where('id','>=',3)->where('sex','=',0)->update(['name'=>881,'age'=>881]);
dd($result);
}
public function select(){
$db=DB::table("user");
$result=$db->where('id','>=',3)->get();
$result=$db->where('id','>=',3)->orWhere('sex','=','1')->get();
foreach($result as $key=>$val){
echo $val->id.'***'.$val->name.'<br />';
}
$result=$db->where('id','=',3)->first();
$result=$db->where('id','>=',3)->value('id');
$result=$db->select('id','name','age')->where('id','>=',3)->offset(2)->limit(3)->orderBy('age','asc')->get();
foreach($result as $key=>$val){
echo $val->id.'***'.$val->name.'****'.$val->name.'<br />';
}
}
}
补充
|