PHPackages                             zfegg/zend-db-feature - 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. zfegg/zend-db-feature

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

zfegg/zend-db-feature
=====================

Zendframework/zend-db TableGateway features.

2.0.0(6y ago)01.1kMITPHPCI failing

Since Apr 26Pushed 6y ago2 watchersCompare

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

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

Zend db features
================

[](#zend-db-features)

Installation / 安装
-----------------

[](#installation--安装)

```
{
    "require": {
        "zfegg/zend-db-feature": "^1.0"
    }
}

```

Usage / 使用说明
------------

[](#usage--使用说明)

### TableGatewayAbstractServiceFactory 使用

[](#tablegatewayabstractservicefactory-使用)

`TableGatewayAbstractServiceFactory` 方便及明了的配置数据库和获取 `TableGateway` 对象. 下面介绍使用和配置

#### 1. 确认`ServiceManager` 中以下两个抽象工厂类，以`module.config.php`为例子：

[](#1-确认servicemanager-中以下两个抽象工厂类以moduleconfigphp为例子)

```
use Zfegg\Db\TableGateway\Factory\TableGatewayAbstractServiceFactory;
use Laminas\Db\Adapter\AdapterAbstractServiceFactory;

return [
    'service_manager' => [
        'abstract_factories' => [
            TableGatewayAbstractServiceFactory::class,
            AdapterAbstractServiceFactory::class,
        ]
    ]
];
```

#### 2. 数据库配置,`Laminas\Db\Adapter\AdapterAbstractServiceFactory` 实现了多DbAdapter(数据库适配器)的获取.

[](#2-数据库配置laminasdbadapteradapterabstractservicefactory-实现了多dbadapter数据库适配器的获取)

```
return [
    'db' => [
        'adapters' => [
            'db' => [  //Default
              'driver'   => 'pdo_mysql',
              'host'     => 'localhost',
              'database' => 'test',
              'username' => 'root',
              'password' => '',
              'charset'  => 'utf8',
            ],
            'db.name1' => [
              'driver'   => 'pdo_mysql',
              'host'     => 'localhost',
              'database' => 'test',
              'username' => 'root',
              'password' => '',
              'charset'  => 'utf8',
            ],
            'db.name2' => [
              'driver'   => 'pdo_mysql',
              'host'     => 'localhost',
              'database' => 'test',
              'username' => 'root',
              'password' => '',
              'charset'  => 'utf8',
            ],
        ]
    ]
];
```

在 `ServiceManager` 中获取方式:

```
$serviceManager->get('db');
$serviceManager->get('db.name1');
$serviceManager->get('db.name2');
```

#### 3. `TableGatewayAbstractServiceFactory`, 实现了多表的配置:

[](#3-tablegatewayabstractservicefactory-实现了多表的配置)

```
return [
  'tables' => [
      'Demo1Table' => [
          'table' => 'users',  //Table name
          //'adapter' => 'db', //Set TableGateway adapter `$container->get($config['adapter'] ?: 'db'])`, Default 'db'
          //'schema' => 'test', //Set table schema
      ],
      'Demo2Table' => [
         'table' => 'users',  //Table name
         'invokable' => 'MyApp\\Model\\UserTable', //需要实例返回某个类，类必须是继承 `AbstractTableGateway`
      ],
      Demo3Table::class => [
          'table' => 'users',  //Table name
          'row' => true, //true will call `$table->getResultSetPrototype()->setArrayObjectPrototype(Laminas\Db\RowGateway\RowGateway);`
          //'row' => 'MyApp\\Model\\UserEntity', //set custom ArrayObjectPrototype
          //'primary' => 'id',
      ]
  ],
];
```

在 `ServiceManager` 中获取方式:

```
$serviceManager->get('Demo1Table'); //Instance of Laminas\Db\TableGateway
$serviceManager->get('Demo2Table'); //Instance of MyApp\Model\UserTable
$serviceManager->get(Demo3Table::class); //Instance of Laminas\Db\TableGateway
```

#### 4. 使用实例

[](#4-使用实例)

```
use Zfegg\Db\TableGateway\Factory\TableGatewayAbstractServiceFactory;
use Laminas\Db\Adapter\AdapterAbstractServiceFactory;
use Laminas\ServiceManager\ServiceManager;

$container = new ServiceManager(); //Zend ServiceManager v3
$container->configure([
  'abstract_factories' => [
      TableGatewayAbstractServiceFactory::class,
      AdapterAbstractServiceFactory::class,
  ]
]);
$container->setService('config', [
  'tables' => [
      'TestTable' => [
          'table' => 'user',
          //'invokable' => 'MyApp\\Model\\UserTable',
          'row' => true, //true will call `$table->getResultSetPrototype()->setArrayObjectPrototype(Laminas\Db\RowGateway\RowGateway);`
          //'row' => 'MyApp\\Model\\UserEntity', //set custom ArrayObjectPrototype
          'primary' => 'id',
          //'schema' => 'test',
          //'adapter' => 'db', //Set TableGateway adapter `$container->get($config['adapter'] ?: 'db'])`
      ]
  ],
  'db' => [
      'adapters' => [
          'db' => [
              'driver'   => 'pdo_mysql',
              'host'     => 'localhost',
              'database' => 'test',
              'username' => 'root',
              'password' => '',
              'charset'  => 'utf8',
          ],
      ]
  ]
]);

var_dump($container->has('TestTable'));
$table = $this->container->get('TestTable'); //TableGateway object

//TableGateway CommonCallFeature
$table->find(1);  //SELECT `user`.* FROM `user` WHERE `id` = 1

//If config ['row' => true]
$rowGateway = $table->create(['fullName' => 'test', 'email' => 'test@test.com']);
$rowGateway->save();

//Fetch count
//SELECT count(1) AS `Zfegg_Db_Count` FROM `user` WHERE `email` = 'test@test.com'
$total = $table->fetchCount(['email' => 'test@test.com']);

//Fetch to Paginator object
/** @var \Laminas\Paginator\Paginator $paginator */
$paginator = $table->fetchPaginator(['email' => 'test@test.com']);

//SELECT count(1) AS `Zfegg_Db_Count` FROM `user` WHERE `email` = 'test@test.com'
$paginator->getTotalItemCount()';

//SELECT `user`.* FROM `user` WHERE `email` = 'test@test.com' LIMIT 10 OFFSET 0
$paginator->getCurrentItems()';

//DELETE FROM `user` WHERE `id` = '1'
$table->deletePrimary(1);

//INSERT INTO `user` (`fullName`, `email`) VALUES ('test', 'test@test.com')
$table->save(['fullName' => 'test', 'email' => 'test@test.com']);

//UPDATE `user` SET `fullName` = 'test', `email` = 'test@test.com' WHERE `id` = 1
$table->save(['id' => 1, 'fullName' => 'test', 'email' => 'test@test.com']);
```

License
-------

[](#license)

See [MIT license File](LICENSE)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Total

5

Last Release

2359d ago

Major Versions

1.1.2 → 2.0.02020-01-14

### Community

Maintainers

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

---

Top Contributors

[![Moln](https://avatars.githubusercontent.com/u/2050694?v=4)](https://github.com/Moln "Moln (11 commits)")

---

Tags

zendfeaturedbzfegg

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/zfegg-zend-db-feature/health.svg)

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

###  Alternatives

[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k47.9M443](/packages/robmorgan-phinx)[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.2M137](/packages/phpfastcache-phpfastcache)[spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

8453.1M62](/packages/spatie-laravel-translation-loader)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[laminas/laminas-db

Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations

14023.2M227](/packages/laminas-laminas-db)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

134979.2k1](/packages/danielme85-laravel-log-to-db)

PHPackages © 2026

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