控制器代码
Home.php
<?php
namespace App\Http\Controllers;
use DB;
class Home extends Controller{
// 数据库查询
public function get(){
echo '<pre>';
$res = DB::select('select * from users');
print_r($res);
}
//数据库更新
public function gxupdata(){
$res = DB::update('update users set name="我知道,最好的语言:php25岁了" where id=1');
var_dump($res);
}
//数据库新增
public function xzupdata(){
$res = DB::insert('insert users(`name`,`email`,`password`)values("mignzi","ad@s.com","aginogsg")');
var_dump($res);
}
//删除数据
public function delete(){
$res = DB::delete("delete from users where id=5");
var_dump($res);
}
}
路由代码
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('v');
// echo date('Y-m-d h:i:s');
});
Route::get('/article/p/aaa', function () {
// return view('v');
echo date('Y-m-d h:i:s');
});
Route::get('/db','Home@get');
Route::get('/dbgx','Home@gxupdata');
Route::get('/dbxz','Home@zxupdata');
Route::get('/dbxz','Home@delete');
效果
新增
修改:
删除:
查询: