gpt4 book ai didi

php - 在 Zend Framework 2 中生成具有多个数据库连接的 Doctrine 2 实体

转载 作者:行者123 更新时间:2023-11-29 03:34:08 26 4
gpt4 key购买 nike

对于 Web 应用程序,我必须使用 3 个独立的数据库:

  • MySQL 用于所有应用程序逻辑,例如登录
  • 用于插入记录的 MSSQL Server
  • 用于插入记录的 Oracle 服务器

现在我已经阅读了很多教程和手册来配置这些数据库,所以现在看起来像这样:

doctrine.global.php

return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => '123.123.123.123',
'port' => '3306',
'dbname' => 'db_name',
),
),
'orm_oracle' => array(
'driverClass' => 'Doctrine\DBAL\Driver\OCI8\Driver',
'params' => array(
'host' => '321.321.321.321',
'port' => '1521',
'dbname' => 'something',
'driver' => 'oci8',
'servicename' => 'something',
),
),
'orm_microsoft' => array(
'driverClass' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
'params' => array(
'host' => '231.231.231.231',
'port' => '1433',
'dbname' => 'something',
'driver' => 'sqlsrv',
),
),
)
)
);

doctrine.local.php*

return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'user' => 'brportal',
'password' => '27607097b4',
),
),
//Alternative DB connection
'orm_oracle' => array(
'driverClass' => 'Doctrine\DBAL\Driver\OCI8\Driver',
'params' => array(
'user' => 'joost',
'password' => '4b58tL8DFv7G',
),
),
'orm_microsoft' => array(
'driverClass' => 'Doctrine\DBAL\Driver\SQLSrv\Driver',
'params' => array(
'user' => 'joost',
'password' => '4b58tL8DFv7G',
),
),
),
'entitymanager' => array(
'orm_default' => array(
'connection' => 'orm_default',
'configuration' => 'orm_default',
),
'orm_oracle' => array(
'connection' => 'orm_oracle',
'configuration' => 'orm_oracle',
),
'orm_microsoft' => array(
'connection' => 'orm_microsoft',
'configuration' => 'orm_microsoft',
),
),

// Use array cache locally, also auto generate proxies on development environment.
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'generate_proxies' => true,
),
'orm_oracle' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'generate_proxies' => true,
),
'orm_microsoft' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'generate_proxies' => true,
),
),
)
);

Module.php

'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '\..\src\\' . __NAMESPACE__ . '\Entities')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entities' => __NAMESPACE__ . '_driver'
)
),
'oracle_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '\..\src\\' . __NAMESPACE__ . '\Entities\Oracle')
),
'orm_oracle' => array(
'drivers' => array(
__NAMESPACE__ . '\Entities\Oracle' => 'oracle_driver'
)
),
'microsoft_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '\..\src\\' . __NAMESPACE__ . '\Entities\Microsoft')
),
'orm_microsoft' => array(
'drivers' => array(
__NAMESPACE__ . '\Entities\Microsoft' => 'microsoft_driver'
)
)
)
)

但是现在,我真的很想有一种简单的方法来(重新)生成 mssql 和 oracle 数据库实体(注释)。它已经适用于 MySQL 数据库,但我无法找到如何使用 doctrine-module orm:convert-mapping 指定数据库连接。

我想知道是否有人可以帮我解决这个问题?

提前谢谢大家!

ps: 我已经读过: Zend Framework 2 and Doctrine 2 - Configuration for multiple databases

最佳答案

底线是 ZF2 DoctrineORM 模块不支持它。有一个 feature request for it on the repo .

与此同时,有一个模块提供了一个 shim 模块,它添加了 --em 选项 https://github.com/SwissEngine/Doctrine-Module-Extension

关于php - 在 Zend Framework 2 中生成具有多个数据库连接的 Doctrine 2 实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25864871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com