To use multiple database connections, you must define separate configurations for each connection across several service manager keys. For a connection named orm_crawler, you need to define:
doctrine.connection.orm_crawler: Connection parameters (driver, host, user, etc.).doctrine.configuration.orm_crawler: ORM configuration (caches, proxy settings, etc.).doctrine.driver.orm_crawler: Metadata drivers (e.g., Annotation or DriverChain).doctrine.entitymanager.orm_crawler: Links the specific connection and configuration.doctrine.eventmanager.orm_crawler, doctrine.sql_logger_collector.orm_crawler, and doctrine.entity_resolver.orm_crawler.
The AbstractDoctrineServiceFactory will automatically create these objects. You can then retrieve them from the Laminas Service Manager using the keys doctrine.connection.orm_crawler, doctrine.entitymanager.orm_crawler, etc.
return [
'doctrine' => [
'connection' => [
'orm_crawler' => [
'driverClass' => \Doctrine\DBAL\Driver\PDO\MySQL\Driver::class,
'eventmanager' => 'orm_crawler',
'configuration' => 'orm_crawler',
'params' => [
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'root',
'dbname' => 'crawler',
'driverOptions' => [
1002 => 'SET NAMES utf8',
],
],
],
],
'configuration' => [
'orm_crawler' => [
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'driver' => 'orm_crawler_chain',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'filters' => [],
],
],
'driver' => [
'orm_crawler_annotation' => [
'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
'cache' => 'array',
'paths' => [
__DIR__ . '/../src/Crawler/Entity',
],
],
'orm_crawler_chain' => [
'class' => \Doctrine\ORM\Mapping\Driver\DriverChain::class,
'drivers' => [
'Crawler\Entity' => 'orm_crawler_annotation',
],
],
],
'entitymanager' => [
'orm_crawler' => [
'connection' => 'orm_crawler',
'configuration' => 'orm_crawler',
],
],
'eventmanager' => [
'orm_crawler' => [],
],
'sql_logger_collector' => [
'orm_crawler' => [],
],
'entity_resolver' => [
'orm_crawler' => [],
],
],
];