Blogger Information
Blog 26
fans 2
comment 0
visits 24236
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel 数据库基本操作
leverWang
Original
754 people have browsed it

配置路由
Route::get('test','Test@querys');
Route::get('test/update','Test@updates');
Route::get('test/inserts','Test@inserts');
Route::get('test/del','Test@del');

控制器test.php

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. class Test extends Controller
  5. {
  6. public function querys()
  7. {
  8. // $res['datalist'] =DB::select("select * from user");
  9. // $res['datalist']= DB::table('user')->get()->all();
  10. // 条件查询
  11. // $res['datalist']= DB::select('select * from user where uid = :id', ['id' => 2]);
  12. $res['datalist'] = DB::table('user')->where(['uid' => 2])->get();
  13. return view("querys", $res);
  14. }
  15. public function updates()
  16. {
  17. // 原生更新操作
  18. // $res=DB::update('update user set email = :e where uid=:id',['e'=>'5689@qq.com','id'=>3]);
  19. $res = DB::table('user')->where(['uid' => 1])->update(['email' => 'df688@163.com']);
  20. var_dump($res);
  21. }
  22. public function inserts(){
  23. // 增加操作
  24. // $res=DB::insert('insert user set username=:n, email = :e ',['n'=>'sam','e'=>'kkk@hotmail.com']);
  25. $res=DB::table('user')->insert(['username'=>'小白','email'=>'s33@qq.com']);
  26. var_dump($res);
  27. }
  28. public function del(){
  29. // $res=DB::delete("delete from user where uid=:id",['id'=>5]);
  30. $res=DB::table('user')->where(['uid'=>4])->delete();
  31. var_dump($res);
  32. }
  33. }
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:作业有点不走心呀, 下次多写点
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post