# DB façade 方式

## 配置访问路由

`routes/web.php文件中配置`

```php
Route::any('FacadesTest', ['uses' => 'StudentController@FacadesTest']);
```

## 控制器

文件示例`App\Http\Controllers\StudentController`

```php
<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
class StudentController extends Controller
{

    public function FacadesTest()
    {
        // 新增
       $bool = DB::insert('insert into student(name, age) values(?, ?)',
           ['imooc', 19]);
       var_dump($bool);

        // 更新
       $num = DB::update('update student set age = ? where name = ?',
           [20, 'sean']);
       var_dump($num);

        // 查询
       $students = DB::select('select * from student where id > ?',
           [1001]);
       dd($students);

        // 删除
        $num = DB::delete('delete from student where id > ?', [1001]);
        var_dump($num);

    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/laravel/laravel-ji-chu/shu-ju-ku-cao-zuo/db-facade-fang-shi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
