PHPackages                             guanhui07/database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. guanhui07/database

ActiveLibrary[Database &amp; ORM](/categories/database)

guanhui07/database
==================

The Swoole Pool Database package.

1.2.3(1y ago)46111MITPHPPHP &gt;=7.4.0

Since Feb 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/guanhui07/database)[ Packagist](https://packagist.org/packages/guanhui07/database)[ RSS](/packages/guanhui07-database/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (3)Versions (8)Used By (1)

### 基于Swoole 封装的`连接池`以及适配了`illuminate/database`

[](#基于swoole-封装的连接池以及适配了illuminatedatabase)

###### 目前基于PDO规范 支持MySQL，SQL Server，Postgres和SQLite。

[](#目前基于pdo规范-支持mysqlsql-serverpostgres和sqlite)

#### 1. 安装

[](#1-安装)

```
composer require guanhui07/database

```

#### 2. 创建`配置`实例

[](#2-创建配置实例)

```
/**
 * 创建配置
 */
(new \Guanhui07\SwooleDatabase\PDOConfig())->
withDriver('mysql')-> // 驱动类型
withHost('127.0.0.1')-> // 主机地址
withDbname('test')-> // 数据库名
withUsername('root')-> // 用户名
withPassword('123456')-> // 密码
withCharset('utf8mb4')-> // 字符集编码
setConfig('default'); // 设置全局访问(默认为default)
```

#### 3. 设置

[](#3-设置)

```
\Guanhui07\SwooleDatabase\PoolManager::addPool(64,'default'); // 设置指定连接池尺寸(连接名称默认为 default)
```

#### 4. 使用协程环境模拟Swoole 的任务执行

[](#4-使用协程环境模拟swoole-的任务执行)

```
/**
 * 开启协程(如果框架内已经开启可忽略)
 */
\Swoole\Runtime::enableCoroutine();
/**
 * 协程化IO钩子
 */
\Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL]);
/**
* 记录开始时间
 */
$s = microtime(true);
\Swoole\Coroutine\run(function () {
    /**
     * 循环创建协程(模拟HTTP 请求 执行任务)
     */
    for ($i = 0; $i < 20; $i++) {
        \Swoole\Coroutine::create(function () {
            /**
             * 创建表
             */
//            \Guanhui07\SwooleDatabase\Manager::schema()->create('test',function(\Illuminate\Database\Schema\Blueprint $table){
//                $table->increments('id');
//                $table->string('name')->nullable()->default(1);
//                $table->timestamps();
//            });
            /**
             * 模型查询
             */
//            $lists = \Guanhui07\SwooleDatabase\Model::query()->first();
            /**
             * Connection 直接查询
             */
            $lists = \Guanhui07\SwooleDatabase\Adapter\Manager::table('bd_live_plan')->first();
            var_dump(boolval($lists));
            /**
             * 协程销毁会自动归还连接(不需要手动处理)
             */
        });
    }
});
echo '所有任务用了:' . (microtime(true) - $s) . '秒';
```

### model 用法和laravel orm 一致

[](#model--用法和laravel-orm-一致)

```
class UserModel extends \Guanhui07\SwooleDatabase\Adapter\Model
{
    protected $table = 'user';

}
```

类laravel orm DB
---------------

[](#类laravel-orm-db)

```
use Guanhui07\SwooleDatabase\Adapter\Manager as DB ;

$test = DB::table('user')->where('id', '>', 1)
    ->orderBy('id', 'desc')->limit(2)->get(['id']);
print_r($test->toArray());
$test = DB::select('select 1');
var_dump($test);
```

我的其他包：
------

[](#我的其他包)

 借鉴Laravel实现的 PHP Framework ，FPM模式、websocket使用的workerman、支持容器、PHP8特性attributes实现了路由注解、中间件注解、Laravel Orm等特性

 Swoole模式下 Redis连接池

 facade、门面 fpm模式下可使用

 基于swoole实现的crontab秒级定时任务

 php定时器，参考了workerman源码 实现一个单进程(守护进程)的定时器。

 基于 illuminate/database 做的连接池用于适配Swoole的协程环境

 高性能PHP Framework ，Cli模式，基于Swoole实现，常驻内存，协程框架，支持容器、切面、PHP8特性attributes实现了路由注解、中间件注解、支持Laravel Orm等特性

 open-ai chatgpt调用

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Recently: every ~156 days

Total

7

Last Release

606d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5820457?v=4)[royee](/maintainers/guanhui07)[@guanhui07](https://github.com/guanhui07)

---

Tags

databaseilluminate-databasemysqlormphpswoolelaravelormsqlswooleDatabses

### Embed Badge

![Health badge](/badges/guanhui07-database/health.svg)

```
[![Health](https://phpackages.com/badges/guanhui07-database/health.svg)](https://phpackages.com/packages/guanhui07-database)
```

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k41.3M596](/packages/spatie-laravel-medialibrary)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[dbout/wp-orm

WordPress ORM with Eloquent.

12910.2k1](/packages/dbout-wp-orm)[bigsinoos/j-eloquent

Convert eloquent date attributes to jalali (Persian) dates on the fly. (supports model propery access, toJson, toString and toArray).

214.7k](/packages/bigsinoos-j-eloquent)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
