I am in the process of learning Zend Framework and I am trying to understand how to set up connections to databases.
I understand a few way to do it, but I would like to understand how the quickstart application in the zend tutorial passes the database parameters in the application.ini file into the code. The page in question is here:
http://framework.zend.com/manual/en/learning.quickstart.create-model.html.
I can see no explicit call to get the parameters and I am assuming it is something to do with how the following class works.
class Application_Model_DbTable_Guestbook extends Zend_Db_Table_Abstract
Could someone tell me how this application is getting the details for the database from the application.ini file?
Many thanks
The DB adapter is set up using the Zend_Application_Resource_Db plugin.
The bootstrap calls the plugin with the settings from the db section of the ini file of the application. It creates an adapter, and then sets it as the default adapter for Zend_Db_Table, using the static setDefaultAdapter method.
This is then used as the adapter for all tables (which extend Zend_Db_Table_Abstract), unless you pass a different adapter to their constructor.
Here’s the documentation for resource plugins.