I have followed http://www.solvingmagento.com/accessing-an-external-database-from-your-magento-module/ and articles by Alan Storm and am stuck on connecting a Magento Module to an external database. [Mage/Core version in 1.6 on this project].
I think the configuration appears correct, but I can't get data to the screen. Instead, actual php code is being displayed. Specifically, the whole Resource class is being displayed.
Here is the relevant controller, model, model resource, and config snippet. I am not sure of the Resource model which should be extended, that may be the problem, but maybe there is something else too?
My Controller
public function indexAction()
{
echo "<h1> Connecting Magento to Developer Store! </h1>";
$externalDataRead = Mage::getModel('developer_integration/customer');
$externalDataRead->load(1, 'user_id');
echo '<pre>';
print_r($externalDataRead->getData());
echo '</pre>';
}
My Model
class Developer_Integration_Model_Customer extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init('developer_integration/customer');
}
}
My Model Resource
class Developer_Integration_Model_Resource_Customer extends Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
{
protected function _construct()
{
$this->_init('developer_integration/customer', 'user_id');
}
}
My config.xml (this may not appear well-formatted here, but is in file)
<models>
<developer_integration><!-- name of the model configuration-->
<class>Developer_Integration_Model</class><!-- path where to look for model classes for-->
<resourceModel>developer_integration_resource</resourceModel><!-- pointer to the resource model configuration node-->
</developer_integration>
<developer_integration_resource><!-- resource model configuration name -->
<class>Developer_Integration_Model_Resource</class><!-- path where to look for resource model classes for -->
<entities><!-- entities list -->
<customer><!-- our test entity -->
<table>dev_customer</table><!-- name of the external table to store data for our entity -->
</customer>
</entities>
</developer_integration_resource>
</models>
<resources>
<developer_integration_setup><!-- name of the external db connection -->
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[devuser]]></username>
<dbname><![CDATA[dev_store]]></dbname>
<type><![CDATA[pdo_mysql]]></type>
<active>1</active>
</connection>
</developer_integration_setup>
<developer_integration_write><!-- connection used for write access -->
<connection>
<use>developer_integration_setup</use>
</connection>
</developer_integration_write>
<developer_integration_read><!-- connection used for read access -->
<connection>
<use>developer_integration_setup</use>
</connection>
</developer_integration_read>
</resources>