2011-01-11 6 views
8

Magento에서 일부 외부 데이터베이스에 연결해야합니다. 하나의 튜토리얼을 Create an external database connection in Magento으로 찾았습니다. 이 자습서는 도움이되었으며 하나의 외부 데이터베이스에 연결하는 데 유용했습니다. 그러나 하나 이상의 외부 데이터베이스를 연결해야합니다.Magento에서 여러 외부 데이터베이스를 연결하는 방법은 무엇입니까?

Magento에서 둘 이상의 외부 데이터베이스 (5 개의 외부 데이터베이스라고 가정)에 어떻게 연결할 수 있습니까?

+0

프로그래밍 문제가 아니기 때문에이 유형의 질문은 실제로 스택 오버플로에 속하지 않습니다. http://area51.stackexchange.com/proposals/25439/magento를보고 적절한 질문을 던지십시오. – Sturm

답변

2

나는 외부 데이터베이스 시스템에 연결하는 데 도움이 될 것입니다이 하나 개 젠토 모듈을 발견했다. http://subesh.com.np/2012/02/magento-external-database-connector-v1-0-0-released/

나는 모듈을 시험해 보았다. 잘 작동하고있는 것 같다. 도움이되기를 바랍니다.

편집 :

모듈은 Magento Connect에서도 사용할 수 있습니다. http://www.magentocommerce.com/magento-connect/sp-edb-4574.html

+0

링크가 죽었습니다. 신선한 ULR이 있습니까? 라이브 사이트에서 이것이 어떻게 작동했는지에 대한 후속 의견이 있습니까? –

5

테스트하지는 않았지만 global\resources 아래의 externaldb_* 노드를 다른 고유 한 리소스 이름과 중복시키는 것이 좋습니다. externaldb2_*이 작동해야합니다.

<global> 
<resources> 
    <externaldb_write> 
    <connection> 
     <use>externaldb_database</use> 
    </connection> 
    </externaldb_write> 
    <externaldb_read> 
    <connection> 
     <use>externaldb_database</use> 
    </connection> 
    </externaldb_read> 
    <externaldb_setup> 
    <connection> 
     <use>core_setup</use> 
    </connection> 
    </externaldb_setup> 
    <externaldb_database> 
    <connection> 
     <host><![CDATA[localhost]]></host> 
     <username><![CDATA[db_username]]></username> 
     <password><![CDATA[db_password]]></password> 
     <dbname><![CDATA[db_name]]></dbname> 
     <model>mysql4</model> 
     <type>pdo_mysql</type> 
     <active>1</active> 
    </connection> 
    </externaldb_database> 
    <externaldb2_write> 
    <connection> 
     <use>externaldb2_database</use> 
    </connection> 
    </externaldb2_write> 
    <externaldb2_read> 
    <connection> 
     <use>externaldb2_database</use> 
    </connection> 
    </externaldb2_read> 
    <externaldb2_setup> 
    <connection> 
     <use>core_setup</use> 
    </connection> 
    </externaldb2_setup> 
    <externaldb2_database> 
    <connection> 
     <host><![CDATA[localhost2]]></host> 
     <username><![CDATA[db2_username]]></username> 
     <password><![CDATA[db2_password]]></password> 
     <dbname><![CDATA[db2_name]]></dbname> 
     <model>mysql4</model> 
     <type>pdo_mysql</type> 
     <active>1</active> 
    </connection> 
    </externaldb2_database> 
</resources> 

+2

Jonathan에게 답장을 보내 주셔서 감사합니다. 그러나 Magento 방식으로 데이터를 가져 오려고합니다 (Magento 모델 사용/생성). externaldb2 노드를 추가 한 후 Magento 모델에서 어떻게 사용할 수 있습니까? 예제 링크에서와 같이 externaldb 노드는 모델을 정의하는 데 사용됩니다. externaldb2에 대한 모델을 어떻게 비슷하게 정의 할 수 있습니까? –

+0

@chapagain, 똑같은 일을하고, 다른 모듈에 모델을 넣고, 모듈 설정에서 리소스로 두 번째 데이터베이스를 만들고, 할 일을 할 수 있습니다. 단지 두 번째 모듈에서 모델을 호출합니다. 첫 번째를 통해 – sucitivel

4

할 수 있습니다 모듈이 항상 특정 데이터 소스를 사용하거나에 의해 설명 된대로 글로벌 구성 XML에 지정할 수 있도록, 모듈의 등/config.xml 파일에 사용되는 리소스를 지정 이전 대답이면이 연결이 기본적으로 사용됩니다.

당신은 당신의 코드에서 리소스를 변경할 수 있습니다

$resource = Mage::getSingleton(‘core/resource’); 
$conn  = $resource->getConnection(‘externaldb2_read’); 
0

내가 알 수있는 한, 동일한 모듈 내에서 여러 데이터베이스 소스에 연결하는 모델을 가질 수 없습니다.

내가 한 것은 병렬 더미 모듈을 만드는 것으로, 대체 데이터베이스에 연결해야하는 모델 만 포함되어 있습니다. 따라서 모든 작업을 수행하는 모듈은 하나의 브랜치에 있고 더미 모듈은 다른 데이터베이스와 통신하기 위해 분리되어 있습니다. 문제를 아름답게 해결하지만 가장 세련된 해결책은 아니지만 그다지 우아하지는 않습니다.

관련 문제