Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:弄懂了就好
` public function sel3()
{
$data = DB::table(‘article’)->get()->toArray();
return view('article.article3',['res'=>$data]);
}
public function myadd1()
{
$data = DB::table('article')
->insert(['title'=>'构造器插入数据','fb_date'=>'2019-12-31',
'soure'=>'北京','ydl'=>'22','pls'=>'33','image'=>'b.gif',
'detail'=>'构造器插入数据','cate_id'=>'3']);
print_r($data);
return view('article.article',['res'=>$data]);
}
// 插入 构造器
public function myadd2()
{
$data = DB::table('article')
->insert([
['title'=>'构造器插入数据多条记录1','fb_date'=>'2019-12-31',
'soure'=>'北京','ydl'=>'22','pls'=>'33','image'=>'b.gif',
'detail'=>'构造器插入数据','cate_id'=>'3'],
['title'=>'构造器插入数据多条记录2','fb_date'=>'2019-12-31',
'soure'=>'北京','ydl'=>'22','pls'=>'33','image'=>'b.gif',
'detail'=>'构造器插入数据','cate_id'=>'3']
]);
print_r($data);
return view('article.article',['res'=>$data]);
}
// 插入 构造器
public function myadd3()
{
$data = DB::table('article')
->insertGetId(
['title'=>'构造器插入数据自动获得id','fb_date'=>'2019-12-31',
'soure'=>'北京','ydl'=>'22','pls'=>'33','image'=>'b.gif',
'detail'=>'构造器插入数据','cate_id'=>'3']
);
print_r($data);
return view('article.article',['res'=>$data]);
}
// 修改 构造器
public function upd1()
{
$data =DB::table('article')
->where('article_id',31)
// ->update([‘title’=>’构造器修改数据’]);
->update([‘title’=>’构造器修改数据’,’detail’=>’构造器修改数据’]);
print_r($data);
return view('article.article',['res'=>$data]);
}
// 删除 构造器
public function mydel1()
{
$data =DB::table('article')
->where('article_id','34')
->delete();
print_r($data);
return view('article.article', ['res' => $data]);
}`
` public function myfile()
{
$res =DB::table(‘article’)
->select(‘article_id’,’title’,’fb_date’,’soure’,’ydl’,’pls’,’image’,’detail’,’cate_id’)
->where(‘article_id’,’>’,10)
->whereIn(‘cate_id’,[2,3])
->whereBetween(‘article_id’,[17,30])
->orderBy(‘article_id’,’desc’)
->get()
->toArray();
return view('dbtest.test',['data'=>$res]);
}
public function myjh()
{
$res =DB::table('article')
->count();
echo '<pre>';
echo $res;
echo '<br>';
$res1 =DB::table('article')
->max('article_id');
print_r($res1);
echo '<br>';
$res2 =DB::table('article')
->select(DB::raw('cate_id,Sum(pls),count(*)'))
->groupBy('cate_id')
->get();
print_r($res2);
echo '<br>';
return view('dbtest.test1',['data'=>$res]);
}
public function mjoins()
{
$res = 0;
$res = DB::table('article')
->join('category','article.cate_id','=','category.cate_id')
->select('article.*','category.name')
->whereIn('article_id',[29,30])
->get();
echo '<pre>';
print_r($res);echo '<br>';
return view('dbtest.test1',['data'=>$res]);
}`