laravel 原生 sql

1.插入数据

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

2.查询语句

$user = DB::select('select * from users where id = ?', [1]);
//我们还 可以看到在执行查询的时候使用了参数绑定,以避免SQL注入。除此之//外还可以使用命名绑定:
$user = DB::select('select * from users where id = :id', [':id'=>1]);

3.更新语句

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

4.删除语句

$deleted = DB::delete('delete from users');
上一篇:coredump简介与coredump原因总结


下一篇:Linux coredump