I've been following this thread but I couldn't get it to work, How do I get my Collection to use a different DB connection?.

I'm trying to load a collection from an external database separate from the main magento database.


        <initstatements>SET NAMES utf8</initstatements>

Then on my collection file (class Custom_Module_Model_Mysql4_Mod_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract):

public function _construct()

    $resource = Mage::getSingleton('core/resource');
    $conn = $resource->getConnection('otherdb_read');


I'm stuck on this part.


If you take a loiok at Mage_Catalog_Model_Resource_Product for an example, you will see that they use __construct():

 * Initialize resource
public function __construct()
         ->setConnection('catalog_read', 'catalog_write');
    // ...

I suggest you emulate that in your model:

public function __construct()
    $this->setConnection('otherdb_read', 'otherdb_write');

I'd also suggest you implement the unit test that Vinai provided as an example into your framework to ensure it's configured correctly for you.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.