Magento uses resources to connect to a database. By default, Magento uses one connection to interact with the database. In this connection, there are resources declared in the config.xml
files of the modules to link the models with the right table.
In this recipe, we will use a Magento connection to read some tables and we will learn how to configure a second connection to another database, such as a third-party system.
Navigate to IndexController
of the Packt_Helloworld
module that we created in Chapter 4, Creating a Module. We will test some connections in the indexController
.
In the following steps, we will explain how to work with multiple database connections in your script:
Paste the following code in the
indexAction
method:$resource = Mage::getSingleton('core/resource'); $connection = $resource->getConnection('core_read'); $results = $connection->query('SELECT * FROM core_store')->fetchAll(); Zend_Debug...