Merge pull request #1020 from putyy/feat-db-doc

Update db.md
This commit is contained in:
黄朝晖 2019-11-24 14:41:55 +08:00 committed by GitHub
commit aa6e793343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,23 @@
[hyperf/database](https://github.com/hyperf/database) 功能十分强大,但也不可否认效率上确实些许不足。这里提供一个极简的 `DB` 组件,支持 `PDO``Swoole Mysql`
## 安装
```bash
composer require hyperf/db
```
## 发布组件配置
该组件的配置文件位于 `config/autoload/db.php`,如果文件不存在,可通过下面的命令来将配置文件发布到骨架去:
```bash
php bin/hyperf.php vendor:publish hyperf/db
```
## 组件配置
默认配置 `autoload/db.php` 如下,数据库支持多库配置,默认为 `default`
默认配置 `config/autoload/db.php` 如下,数据库支持多库配置,默认为 `default`
| 配置项 | 类型 | 默认值 | 备注 |
|:--------------------:|:------:|:------------------:|:--------------------------------:|
@ -51,7 +65,7 @@ use Hyperf\DB\DB;
$db = ApplicationContext::getContainer()->get(DB::class);
$res = $db->query('SELECT * FROM `user` WHERE gender = ?;',[1]);
$res = $db->query('SELECT * FROM `user` WHERE gender = ?;', [1]);
```
@ -62,6 +76,6 @@ $res = $db->query('SELECT * FROM `user` WHERE gender = ?;',[1]);
use Hyperf\DB\DB;
$res = DB::query('SELECT * FROM `user` WHERE gender = ?;',[1]);
$res = DB::query('SELECT * FROM `user` WHERE gender = ?;', [1]);
```