一、数据库更新
1.更新语句
DB:update()
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class homecontr extends Controller
{
// 数据库更新
public function update_db (){
$res = DB::update('update articles set title="基于php开发客户信息管理系统" where id = 6 ');
var_dump($res);
}
}
2.路由
<?php
use Illuminate\Support\Facades\Route;
Route::get('db/update','homecontr@update_db');
实例效果:
二、数据库删除
1.删除语句 DB:delete()
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class homecontr extends Controller
{ // 数据库的删除
public function delete_db(){
$res = DB::delete('delete from articles where id = 6');
var_dump($res);
}
}
2.路由
<?php
use Illuminate\Support\Facades\Route;
Route::get('/db/delete','homecontr@delete_db');
实例效果:
三、更新(插入)
1.更新语句 DB::insert()
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class homecontr extends Controller
{
// 数据库更新(插入)
public function insert_db(){
$res = DB::insert('insert into articles (id,title) values(6,"2020年最新5个简洁优秀的个人博客模板免费下载")');
var_dump($res);
}
}
2.路由
<?php
use Illuminate\Support\Facades\Route;
Route::get('/db/insert','homecontr@insert_db');
实例效果:
总结:
配置数据库连接后,调用三个语句,配置路由,完成数据库的增删改:
DB::insert()、DB::delete()、DB::update()