Download the PHP package zfegg/zend-db-feature without Composer
On this page you can find all versions of the php package zfegg/zend-db-feature. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package zend-db-feature
Zend db features
Installation / 安装
Usage / 使用说明
TableGatewayAbstractServiceFactory 使用
TableGatewayAbstractServiceFactory
方便及明了的配置数据库和获取 TableGateway
对象.
下面介绍使用和配置
1. 确认ServiceManager
中以下两个抽象工厂类,以module.config.php
为例子:
2. 数据库配置,Laminas\Db\Adapter\AdapterAbstractServiceFactory
实现了多DbAdapter(数据库适配器)的获取.
在 ServiceManager
中获取方式:
3. TableGatewayAbstractServiceFactory
, 实现了多表的配置:
在 ServiceManager
中获取方式:
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' => '[email protected]']);
$rowGateway->save();
//Fetch count
//SELECT count(1) AS `Zfegg_Db_Count` FROM `user` WHERE `email` = '[email protected]'
$total = $table->fetchCount(['email' => '[email protected]']);
//Fetch to Paginator object
/** @var \Laminas\Paginator\Paginator $paginator */
$paginator = $table->fetchPaginator(['email' => '[email protected]']);
//SELECT count(1) AS `Zfegg_Db_Count` FROM `user` WHERE `email` = '[email protected]'
$paginator->getTotalItemCount()';
//SELECT `user`.* FROM `user` WHERE `email` = '[email protected]' LIMIT 10 OFFSET 0
$paginator->getCurrentItems()';
//DELETE FROM `user` WHERE `id` = '1'
$table->deletePrimary(1);
//INSERT INTO `user` (`fullName`, `email`) VALUES ('test', '[email protected]')
$table->save(['fullName' => 'test', 'email' => '[email protected]']);
//UPDATE `user` SET `fullName` = 'test', `email` = '[email protected]' WHERE `id` = 1
$table->save(['id' => 1, 'fullName' => 'test', 'email' => '[email protected]']);
License
See MIT license File
All versions of zend-db-feature with dependencies
PHP Build Version
Package Version
Requires
laminas/laminas-db Version
^2.6.2
The package zfegg/zend-db-feature contains the following files
Loading the files please wait ....