rradutzu / zend2-doctrine-dynamic-db
允许使用动态数据库名称定义连接的Zend2/3 Doctrine模块
2.0.0
2023-09-25 12:05 UTC
Requires
- php: ^8.2
- composer/installers: ~1.0
- doctrine/doctrine-orm-module: ^6.0
This package is auto-updated.
Last update: 2024-09-25 14:27:29 UTC
README
允许使用动态数据库名称定义连接的Zend2 Doctrine模块
#使用方法
- 将 'DoctrineDynamicDb' 包含在您的 modules.config.php 文件中
- 将 'dbNameFactory' 参数添加到所使用的连接中。
return array(
//...
'doctrine' => array(
'connection' => array(
//...
'orm_dynamic' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'kotor3',
'dbname' => '%',
// this needs to return instance of DoctrineMultiDbAdapter\Client\ClientInterface,
// a custom object or a string which represents the db name
'dbNameFactory' => 'ClientFactory',
// optional | name of the method used to retrieve the db name if dbNameFactory
// returns a custom object
'dbNameFactoryMethod' => 'getClientDb'
)
)
),
'dynamic_entitymanager' => array(
// need to add the connection to the new entity manager
'orm_dynamic' => array()
)
),
//...
);
3.使用以下方式获取动态连接的实体管理器:
$em = $serviceLocator->get('doctrine.dynamic_entitymanager.##connection_name##');