批改状态:合格
老师批语:laravel对原生sql访问提供了强力支持, 底层仍是基于pdo
DB::select
$res=DB::select("select * from product where id>:id",['id'=>1]);echo '<pre>';print_r($res);return view('product.detail',['product'=>$res]);
DB::update
$res= DB::update('update `product` set `goods_name`="iphone11" where id = 6')
DB::insert
$res= DB::insert('insert into product(`goods_name`,`area`) values("iphone12","上海")');
DB::delete
$res= DB::delete('delete from product where area="上海"');##2、总结一下where方法、whereIn方法、update方法、delete方法等查询构造器的使用方法并写几个案例`查询构造器``where方法````phpecho '<pre>';$res = DB::table('product')->where('id','>',1)->where('area','浙江')->get()->toArray();var_dump($res);
whereIn方法
$res =DB::table('product')->select('id','area','price')->whereIn('id',[1,3,5,6])->get()->toArray();
update方法
$res=DB::table('article_cate')->where('id',9)->update(['title'=>'测试分类50']);
delete方法
$res=DB::table('article_cate')->where('id',9)->delete();
$res=DB::table('article_cate')->insert(['pid'=>0,'ord'=>0,'title'=>'测试分类']);
insert方法只返回布尔型的ture或者false
insertGetId返回插入记录的id值
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号