第一种 :使用DB类 facade实现 CURD
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class UserController extends Controller
{
public function info($id){
// return'member-info-id-'.$id;
//查询数据
$users=DB::select('select * from user where id = :id', ['id' => $id]);
echo "<pre>";
print_r($users);
//插入数据
$users=DB::insert('insert into user(name,age,create_time) values(?,?,?)',['王百万',18,time()]);
var_dump($users);
//修改数据
$affected = DB::update('update user set age = ? where name = ?', [23,'王百万']);
var_dump($affected);
//删除数据(删除数据必须加条件,不然生孩子没屁眼。不要问为什么。)
$deleted = DB::delete('delete from user where id=?',[1]);
var_dump($deleted);
}
}
//路由
Route::any('User/info/{id}',['uses'=>'UserController@info'])
->where('id','[0-9]+');