批改状态:合格
老师批语:不容易,还在坚持写
.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 atitleecho '<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);}

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号