mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-05 05:07:58 +08:00
commit
aa6e793343
@ -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]);
|
||||
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user