1、laravel数据库访问类DB::select、DB::update、DB::insert、DB::delete分别写几个案例
DB:select(查询)
$res = DB::select('select * from student where id>?',[2]);
DB::insert(新增)
$res = DB::insert('insert into student (name) values (?)', ['Dayle']);
DB::update(修改)
$res = DB::update('update student set name = ? where name=?', ['WJF','Dayle']);
DB::delete(删除)
$res = DB::delete('delete from student where name=?',['WJF']);
2、总结一下where方法、whereIn方法、update方法、delete方法等查询构造器的使用方法并写几个案例
where方法
$res = DB::table('student')->select('*')->where('id','>',2)->get();
whereIn方法
$res = DB::table('student')->select('*')->whereIn('id',[1,5,6])->get();
update更新
$res = DB::table('student')->select('*')->whereIn('id',[1,5])->update(['grade'=>88]);
delete删除
$res = DB::table('student')->select('*')->where('id',11)->delete();
3、insert方法插入一条记录和多答记录的方法,并说明和insertGetId方法的异同
insert单条插入
DB::table('student')->insert(
['name'=>'WJF']
);
insert多条插入
DB::table('student')->insert([
['name'=>'WJF'],
['name'=>'WWW']
]
);
insertGetId
$res = DB::table('student')->insertGetId(
['name'=>'WWW']
);