路由:
//验证是否连接成功
Route::get('db_test',function (){
dump(\DB::connection());
});
//DB原生操作
Route::get('db','DbController@db');
控制器:
//原生操作sql
public function db()
{
// 添加
// $sql = "insert into la_user (username,password) values (:username,:password)";
返回true/false
$ret = DB::insert($sql,[':username'=>'amdin',':password'=>'admin123']);
// $ret = DB::insert($sql,['username'=>'user1','password'=>'user1']);
// dump($ret);
// 修改
// $sql = "update la_user set username=:username where id=:id";
// 返回 受影响行数
// $ret = DB::update($sql,['username'=>'张三22','id'=>1]);
// 查看
// $sql = "select * from la_user where id=:id";
//获取数据集合
// $ret = DB::selectOne($sql,['id'=>1]);
// $sql = "select * from la_user";
// 获取数组集合
// $ret = DB::select($sql);
//删除
// $sql = "delete from la_user where id=:id";
// 返回 受影响行数
// $ret = DB::delete($sql,['id'=>1]);
// dump($ret);
}