Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:数据库主要是curd,但只会curd也不行
Laravel 的数据库查询构造器为创建和运行数据库查询提供了一个方便的接口。它可用于执行应用程序中大部分数据库操作,且可在所有支持的数据库系统上运行。
Laravel 的查询构造器使用 PDO 参数绑定来保护您的应用程序免受 SQL 注入攻击。因此没有必要清理作为绑定传递的字符串。
https://learnku.com/docs/laravel/5.7/queries/2289
public function list(){
echo '<pre>';
$res = DB::table('jizhang')->get();
print_r($res);
}
public function fllist(){
echo '<pre>';
$res = DB::table('jizhang')->select('yonghuid as yid','jine')->get();
print_r($res);
}
public function idlist(){
echo '<pre>';
$res = DB::table('jizhang')->select('yonghuid','jine')->where('yonghuid','=',28)->get();
print_r($res);
}
public function likes(){
$res = DB::table('jizhang')->where('beizhu','like','%顺丰%')->get()->all();
echo '<pre>';
print_r($res);
}
public function wherein(){
$res = DB::table('jizhang')->whereIn('id',[1,18,22])->get()->all();
echo '<pre>';
print_r($res);
}
public function joins(){
$res = DB::table('jizhang')->join('users','users.id','=','jizhang.yonghuid')->get()->all();
echo '<pre>';
print_r($res);
}
public function pvs(){
$res=DB::table('jizhang')->avg('pv');
echo $res;
// $avg = 0;
// foreach ($res as $key => $value){
// $avg += $value->pv;
// }
// $avg = $avg/count($res);
// echo '<pre>';
// print_r($avg);
}
public function insert2(){
$item = array('jine'=>50,'zhanghu'=>"现金",'chengyuan'=>"小飞",'beizhu'=>5555,'shijian'=>1589108925,'yonghuid'=>28,'pv'=>50);
$item2 = array('jine'=>50,'zhanghu'=>"现金",'chengyuan'=>"小飞",'beizhu'=>5555,'shijian'=>1589108925,'yonghuid'=>28,'pv'=>50);
$data[] = $item;
$data[] = $item2;
$res = DB::table('jizhang')->insert($data);
var_dump($res);
}
public function insert3(){
$item = array('jine'=>50,'zhanghu'=>"现金",'chengyuan'=>"小飞",'beizhu'=>5555,'shijian'=>1589108925,'yonghuid'=>28,'pv'=>50);
$res = DB::table('jizhang')->insertGetId($item);
var_dump($res);
}
public function update2(){
$res = DB::table('jizhang')->where('id',15)->update(array('jine'=>10500));
var_dump($res);
}
`
public function shanchu(){
$res = DB::table('jizhang')->where('id',16)->delete();
var_dump($res);
}
总结:本节课深入学习了数据库的各种操作,第一次明白了前台的各种筛选条件原来是用数据库的查询语句筛选出来的。