PHPackages                             lulanyin/db - 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. lulanyin/db

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

lulanyin/db
===========

PHP数据库操作类

v1.01(7y ago)1104[1 issues](https://github.com/lulanyin/db/issues)MITPHPPHP &gt;=5.6

Since Jul 18Pushed 4y ago1 watchersCompare

[ Source](https://github.com/lulanyin/db)[ Packagist](https://packagist.org/packages/lulanyin/db)[ RSS](/packages/lulanyin-db/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)DependenciesVersions (3)Used By (0)

PHP 数据库操作类
==========

[](#php-数据库操作类)

### 安装方式

[](#安装方式)

```
composer require inphp/db

```

### 使用方式

[](#使用方式)

```
//config.php

//定义数据库配置文件或配置，填写文件路径（*推荐*）
define("INPHP_DB_CONFIG", ROOT."/config/private/mysql.php");

//或者可以直接设置为值
define("INPHP_DB_CONFIG", ["值请参考下方 return 之后的数组"]);

//数据库配置文件 ROOT."/config/private/mysql.php"
return [
    //是否开启调试
    "debug"         => false,
    //数据遍历方式，具体查看PDO文档
    "fetch_model"   => PDO::FETCH_ASSOC,
    //字符集类型
    "charset"   => "utf8mb4",
    //表名前缀，为了方便使用，读写分离的前缀必须统一
    "prefix"    => 'pre_',
    //超时时间
    'timeout'   => 5,
    //默认连接，若使用读写分离，可以不定义
    "default"       => [
        //服务器地址
        'host'      => '127.0.0.1',
        //端口
        'port'      => 3306,
        //数据库用户名
        'user'      => 'root',
        //密码
        'password'  => '123456',
        //数据库名
        'database'  => 'database'
    ],
    //读分离，若定义了，select 会优先使用
    "read"          => ["数组值请参考上方的 default 连接"],
    //写分离，若定义了，insert update delete 会优先使用
    "write"         => ["数组值请参考上方的 default 连接"],
    //如果有需要 redis, 请定义 redis 连接
    "redis"         => [
        //redis服务器地址
        'host'       => '127.0.0.1',
        //端口
        'port'       => 6379,
        //密码
        'password'   => '',
        //使用第几个库
        'select'     => 0,
        //超时时间
        'timeout'    => 0,
        //过期时间
        'expire'     => 0,
        //持久化
        'persistent' => false,
        //保存的所有 key 的前缀
        'prefix'     => 'redis_pre_',
    ]
];
```

### 支持 Swoole，在 Swoole 服务中请务必设置此常量，数值为连接池的最连接数量

[](#支持-swoole在-swoole-服务中请务必设置此常量数值为连接池的最连接数量)

```
define("INPHP_DB_SWOOLE_POOLS", 10);
```

### 错误日志文件

[](#错误日志文件)

```
//您需要定义一个常量：RUNTIME，并给予此文件夹写入权限，默认保存在 RUNTIME."/db/error.txt" 里边
define("RUNTIME", ROOT."/runtime");
```

### Cache 文件夹的类文件，使用的是 ThinkPHP 中的原文件，当前仅使用到 Redis，其它按需要请自行使用。

[](#cache-文件夹的类文件使用的是-thinkphp-中的原文件当前仅使用到-redis其它按需要请自行使用)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~0 days

Total

2

Last Release

2858d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e7ba8f963b6d1a5d3ab8596777a2397367b19b013111e99f640e564045240178?d=identicon)[lanyin](/maintainers/lanyin)

---

Top Contributors

[![lulanyin](https://avatars.githubusercontent.com/u/5426155?v=4)](https://github.com/lulanyin "lulanyin (7 commits)")

---

Tags

phpdb

### Embed Badge

![Health badge](/badges/lulanyin-db/health.svg)

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

###  Alternatives

[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11812.0k](/packages/stefangabos-zebra-database)[swoft/db

swoft database component

24167.4k11](/packages/swoft-db)[jawira/db-draw

📐 Takes a DoctrineORM connection and generates a database diagram in .puml format

2295.1k2](/packages/jawira-db-draw)[webparking/laravel-db-rebuild

A laravel package that allows for quick database rebuilds with presets.

448.8k](/packages/webparking-laravel-db-rebuild)[simple-swoole/db

A db component for Simps.

216.3k3](/packages/simple-swoole-db)

PHPackages © 2026

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