Blogger Information
Blog 39
fans 0
comment 0
visits 30662
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
lavarel基础1:数据库查询、增加、删除、更新(二)
Original
858 people have browsed it

一、数据库更新

1.更新语句

DB:update()

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. class homecontr extends Controller
  5. {
  6. // 数据库更新
  7. public function update_db (){
  8. $res = DB::update('update articles set title="基于php开发客户信息管理系统" where id = 6 ');
  9. var_dump($res);
  10. }
  11. }

2.路由

  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. Route::get('db/update','homecontr@update_db');

实例效果:

二、数据库删除

1.删除语句 DB:delete()

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. class homecontr extends Controller
  5. { // 数据库的删除
  6. public function delete_db(){
  7. $res = DB::delete('delete from articles where id = 6');
  8. var_dump($res);
  9. }
  10. }

2.路由

  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. Route::get('/db/delete','homecontr@delete_db');

实例效果:

三、更新(插入)

1.更新语句 DB::insert()

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\DB;
  4. class homecontr extends Controller
  5. {
  6. // 数据库更新(插入)
  7. public function insert_db(){
  8. $res = DB::insert('insert into articles (id,title) values(6,"2020年最新5个简洁优秀的个人博客模板免费下载")');
  9. var_dump($res);
  10. }
  11. }

2.路由

  1. <?php
  2. use Illuminate\Support\Facades\Route;
  3. Route::get('/db/insert','homecontr@insert_db');

实例效果:

总结:
配置数据库连接后,调用三个语句,配置路由,完成数据库的增删改:
DB::insert()、DB::delete()、DB::update()

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