PHPackages                             boxphp/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. boxphp/database

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

boxphp/database
===============

BoxPHP Database - PDO Connection, QueryBuilder, Pool

1.0.0(today)00MITPHPPHP &gt;=8.1

Since Jun 27Pushed todayCompare

[ Source](https://github.com/tvjojo/boxphp-database)[ Packagist](https://packagist.org/packages/boxphp/database)[ RSS](/packages/boxphp-database/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

boxphp/database
===============

[](#boxphpdatabase)

BoxPHP 数据库包 - PDO 连接、查询构建器及连接池

安装
--

[](#安装)

```
composer require boxphp/database
```

使用
--

[](#使用)

### PDO 连接

[](#pdo-连接)

```
use BoxPHP\Database\Database\PdoConnection;

$db = new PdoConnection([
    'driver' => 'mysql',
    'host' => '127.0.0.1',
    'port' => 3306,
    'database' => 'myapp',
    'username' => 'root',
    'password' => '',
]);

$db->connect();
$users = $db->select('SELECT * FROM users WHERE id = ?', [1]);
```

### 查询构建器

[](#查询构建器)

```
use BoxPHP\Database\Database\QueryBuilder;

// SELECT
$users = (new QueryBuilder('users'))
    ->select('id', 'name', 'email')
    ->where('status', 'active')
    ->orderBy('created_at', 'DESC')
    ->limit(10)
    ->get();

// INSERT
$id = (new QueryBuilder('users'))
    ->insert(['name' => 'John', 'email' => 'john@example.com']);

// UPDATE
=count = (new QueryBuilder('users'))
    ->where('id', 1)
    ->update(['status' => 'inactive']);

// DELETE
=count = (new QueryBuilder('users'))
    ->where('id', 1)
    ->delete();

// 聚合
$count = (new QueryBuilder('users'))
    ->where('status', 'active')
    ->count();

$sum = (new QueryBuilder('orders'))
    ->where('user_id', 1)
    ->sum('amount');
```

### 连接池

[](#连接池)

```
use BoxPHP\Database\Database\DatabasePool;

$pool = new DatabasePool([
    'driver' => 'mysql',
    'host' => '127.0.0.1',
    'database' => 'myapp',
    'username' => 'root',
    'password' => '',
    'pool_max_size' => 10,
]);

$db = $pool->get();
$users = $db->select('SELECT * FROM users');
$pool->put($db);
```

### 事务

[](#事务)

```
$db->beginTransaction();
try {
    $db->execute('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 1]);
    $db->execute('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 2]);
    $db->commit();
} catch (\Exception $e) {
    $db->rollBack();
    throw $e;
}
```

依赖
--

[](#依赖)

- PHP &gt;= 8.1
- boxphp/core ^1.0
- PDO 扩展

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

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

---

Top Contributors

[![tvjojo](https://avatars.githubusercontent.com/u/9910314?v=4)](https://github.com/tvjojo "tvjojo (5 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

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