I have to connect with some exterior databases from Magento. I discovered one tutorial to Create An External Database Connection in Magento. This tutorial was useful also it labored for hooking up to 1 exterior database. But, I must connect several exterior databases.

How do i connect with several exterior databases (suppose 5 exterior databases) in Magento?

Thanks ahead of time.

I've not examined it, however i would expect that copying the externaldb_* nodes under global\resources with another (unique) resource title e.g. externaldb2_* should work.

<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>

You are able to specify the resource utilized in the module's etc/config.xml file, to ensure that a module will invariably make use of a certain databases or specify within the global config xml as referred to through the previous answer, than the connection is going to be used automatically.

You are able to alter the resource inside your code:

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

I discovered that one Magento Module that can help for connecting to exterior database system. http://www.thethreetree.com/2011/04/magento-external-database-connector-v1-0-0-released/

I attempted the module and appears to become working well.Hope this can help.

So far as I will tell, you cannot have models hooking up to multiple database sources from inside exactly the same module. If you're able to... well F--- me, because I have looked around everywhere for many configuration option that will permit that.

What I have done, is produce a parallel dummy module, that only consists of the model that must connect with the alternate database. Therefore the module that does everything is within one branch, and also the dummy module to speak to another database is separate. Solves the issue superbly, although it isn't probably the most elegant solution... but it is not minimal elegant either )