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

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

zodream/database
================

SQL Builder With PDO, ORM etc

5.3(2y ago)01483MITPHPPHP &gt;=8.2

Since Aug 15Pushed 4d ago1 watchersCompare

[ Source](https://github.com/zodream/database)[ Packagist](https://packagist.org/packages/zodream/database)[ Docs](https://github.com/zodream/database)[ RSS](/packages/zodream-database/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (10)DependenciesVersions (12)Used By (3)

database
========

[](#database)

SQL Builder With PDO, ORM etc

注意 Model 关联查询不支持 方法名驼峰转化
------------------------

[](#注意-model-关联查询不支持-方法名驼峰转化)

`$model->option_items` 不会调用 `$model->optionItems()`

提前预知为空不进行真实数据请求
---------------

[](#提前预知为空不进行真实数据请求)

```
$query->isEmpty();
```

model 判断是否为空 请不要轻易用 empty 关联关系时无法正确判断
-------------------------------------

[](#model-判断是否为空-请不要轻易用-empty-关联关系时无法正确判断)

```
$model = new Model();

$model->setRaelation('a', 122222);

empty($model['a'])  // true

$model->relationLoaded('a') // true
```

关联的特殊用法
-------

[](#关联的特殊用法)

根据商品获取商品属性及属性名，

```
$data = [
    'id' => 1,
    'name' => 2
];
$data = Relation::create($data, [
    't' => [
        'query' => GoodsAttributeModel::query(),
        'link' => ['id', 'goods_id'],
        'relation' => [
            'attr' => [
                'query' => AttributeModel::query(),
                'type' => 0,
                'link' => ['attribute_id', 'id'],
            ]
        ]
    ],
]);
```

最终结果如下

```
{
  "id": 1,
  "name": 2,
  "t": [
    {
      "id": 10000,
      "goods_id": 1,
      "value": "11111",
      "attribute_id": 5,
      "attr": {
        "id": 5,
        "name": "尺寸"
      }
    }
  ]
}
```

多级如果关联名为空则替换上一级，例如

```
$data = [
    'id' => 1,
    'name' => 2
];
$data = Relation::create($data, [
    't' => [
        'query' => GoodsAttributeModel::query(),
        'link' => ['id', 'goods_id'],
        'relation' => [
            [
                'query' => AttributeModel::query(),
                'type' => 0,
                'link' => ['attribute_id', 'id'],
            ]
        ]
    ],
]);
```

最终结果如下

```
{
  "id": 1,
  "name": 2,
  "t": [
    {
        "id": 5,
        "name": "尺寸"
    }
  ]
}
```

###  Health Score

45

↑

FairBetter than 92% of packages

Maintenance65

Regular maintenance activity

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

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

Recently: every ~312 days

Total

11

Last Release

782d ago

Major Versions

v0.1 → v1.02018-01-22

1.2 → 2.02018-09-10

2.1 → 4.02020-10-25

4.0 → 5.02021-03-25

PHP version history (5 changes)v0.1PHP &gt;=5.6.0

4.0PHP &gt;=7.1.0

5.0PHP &gt;=8.0

5.2PHP &gt;=8.1

5.3PHP &gt;=8.2

### Community

Maintainers

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

---

Tags

ormsqlzodream

### Embed Badge

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

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

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[cycle/orm

PHP DataMapper ORM and Data Modelling Engine

1.3k835.4k65](/packages/cycle-orm)[nilportugues/sql-query-builder

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation.

425239.4k6](/packages/nilportugues-sql-query-builder)[atlas/orm

An ORM for your persistence model (not your domain model).

429139.8k12](/packages/atlas-orm)[morris/lessql

LessQL: A lightweight and performant PHP ORM alternative

405140.0k3](/packages/morris-lessql)[tareq1988/wp-eloquent

Eloquent ORM for WordPress

57254.7k](/packages/tareq1988-wp-eloquent)

PHPackages © 2026

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