Blogger Information
Blog 52
fans 0
comment 3
visits 42391
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实战:第3章 laravel基础1与数据增查改删
王小飞
Original
677 people have browsed it

控制器代码

Home.php

  1. <?php
  2. namespace App\Http\Controllers;
  3. use DB;
  4. class Home extends Controller{
  5. // 数据库查询
  6. public function get(){
  7. echo '<pre>';
  8. $res = DB::select('select * from users');
  9. print_r($res);
  10. }
  11. //数据库更新
  12. public function gxupdata(){
  13. $res = DB::update('update users set name="我知道,最好的语言:php25岁了" where id=1');
  14. var_dump($res);
  15. }
  16. //数据库新增
  17. public function xzupdata(){
  18. $res = DB::insert('insert users(`name`,`email`,`password`)values("mignzi","ad@s.com","aginogsg")');
  19. var_dump($res);
  20. }
  21. //删除数据
  22. public function delete(){
  23. $res = DB::delete("delete from users where id=5");
  24. var_dump($res);
  25. }
  26. }

路由代码

  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. /*
  4. |--------------------------------------------------------------------------
  5. | Web Routes
  6. |--------------------------------------------------------------------------
  7. |
  8. | Here is where you can register web routes for your application. These
  9. | routes are loaded by the RouteServiceProvider within a group which
  10. | contains the "web" middleware group. Now create something great!
  11. |
  12. */
  13. Route::get('/', function () {
  14. return view('v');
  15. // echo date('Y-m-d h:i:s');
  16. });
  17. Route::get('/article/p/aaa', function () {
  18. // return view('v');
  19. echo date('Y-m-d h:i:s');
  20. });
  21. Route::get('/db','Home@get');
  22. Route::get('/dbgx','Home@gxupdata');
  23. Route::get('/dbxz','Home@zxupdata');
  24. Route::get('/dbxz','Home@delete');

效果

新增

修改:

删除:

查询:

Correcting teacher:天蓬老师天蓬老师

Correction status:unqualified

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