Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:不容易,还在坚持写
.env
DB_CONNECTION=mysql //数据库类型
DB_HOST=127.0.0.1 //地址
DB_PORT=3306 //端口号
DB_DATABASE=laravel //数据库名
DB_USERNAME=root //数据库用户名
DB_PASSWORD=root //数据库密码
Route::get('/', function () {
// return view('welcome');
return view('test');
// echo date("Y-M-D");
});
// Route::get('/active/p/aaa',function(){
// return 'ppp';
// });
Route::get('/home/index','Home@index');
Route::get('/admins/article/lists','admin\Article@lists');
// 查询数据库
Route::get('/dbselect','Home@get');
// 数据库更新
Route::get('/update','Home@test_update');
// 数据新增
Route::get('/inset','Home@test_inset');
// 数据删除
Route::get('/delete','Home@test_delete');
Route::get('/find','Home@find');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/layui/css/layui.css">
<title>test</title>
</head>
<body>
<table class="layui-table">
<thead>
<tr>
<th>id</th>
<TH>标题</TH>
</tr>
</thead>
<tbody>
<?php foreach($result as $val){?>
<tr>
<td><?php echo $val['id'] ?></td>
<td><?php echo $val['title']?></td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
// 数据库查询原生查询
public function get(){
// select * from atitle
echo '<pre>';
$res = DB::select('select * from atitle where id>2');
//$res = \DB::select('select * from atitle);
print_r($res);
}
// 数据库更新操作原生
public function test_update(){
$res = DB::update('update atitle set title="我知道" where id=2');
var_dump($res);
}
// 数据库新增原生
public function test_inset(){
$res = DB::insert('insert atitle(`id`,`title`)values(5,"sssss")');
var_dump($res);
}
// 数据库删除原生
public function test_delete(){
$res = DB::delete('delete from atitle where id=1');
var_dump($res);
}
// 高级数据库查询方法(链式调用)
public function find(){
// select * from atitle where id=3
$res=DB::table('atitle')->where('id',3)->first();
echo $res->title;
echo '<pre>';
print_r($res);
}