🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
如果配置好数据库连接,就可以通过 DB facade 执行查找。 ## 执行 Select 查找 ~~~ $results = DB::select('select * from users where id = ?', [1]); ~~~ select 方法会返回一个 array 结果。 You may also execute a query using named bindings: ~~~ $results = DB::select('select * from users where id = :id', ['id' => 1]); ~~~ ## 执行 Insert 语法 ~~~ DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']); ~~~ ## 执行 Update 语法 ~~~ DB::update('update users set votes = 100 where name = ?', ['John']); ~~~ ## 执行 Delete 语法 ~~~ DB::delete('delete from users'); ~~~ > 注意: update 和 delete 语法会返回在操作中所影响的数据笔数。 ## 执行一般语法 ~~~ DB::statement('drop table users'); ~~~ ## 监听查找事件 你可以使用 DB::listen 方法,去监听查找的事件: ~~~ DB::listen(function($sql, $bindings, $time) { // }); ~~~