laravel 原生 sql

1.插入數據laravel

DB::insert('insert into users (id, name, email, password) values (?, ?, ? , ? )',[1, 'Laravel','laravel@test.com','123']);

2.查詢語句spa

$user = DB::select('select * from users where id = ?', [1]);
//咱們還 能夠看到在執行查詢的時候使用了參數綁定,以免SQL注入。除此之//外還可使用命名綁定:
$user = DB::select('select * from users where id = :id', [':id'=>1]); 

3.更新語句code

$affected = DB::update('update users set name="LaravelAcademy" where name = ?', ['Academy']);

4.刪除語句blog

$deleted = DB::delete('delete from users');
相關文章
相關標籤/搜索