PHP code example of zfegg / zend-db-feature

1. Go to this page and download the library: Download zfegg/zend-db-feature library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zfegg / zend-db-feature example snippets


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

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

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->get('db');
$serviceManager->get('db.name1');
$serviceManager->get('db.name2');

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->get('Demo1Table'); //Instance of Laminas\Db\TableGateway
$serviceManager->get('Demo2Table'); //Instance of MyApp\Model\UserTable
$serviceManager->get(Demo3Table::class); //Instance of Laminas\Db\TableGateway