Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework database initialisation

in tutorials such as this http://akrabat.com/zend-framework-tutorial/, the database parameters for the application are stored in the application.ini config file. Reading through the docs for zend_db and other database interaction tutorials, it suggests that the database object is created from parameters hard coded into php code. Whats confusing is that there doesnt appear to be any explicit initialisation of the database object in tutorials such as the one above. So my natural conclusion to this is that the database object is automatically generated from the parameters provided in the application.ini config file?

like image 485
richzilla Avatar asked Aug 13 '26 09:08

richzilla


1 Answers

So my natural conclusion to this is that the database object is automatically generated from the parameters provided in the application.ini config file?

Kind of, in fact, there are a few step before your database get initialized.

  1. Your application is bootstraped
  2. It reads the config file
  3. When a resource.* is found, check if the according resource class exists
  4. The resource class initialize an object with the given parameter
    1. Zend_Db_Table has a static method setDefaultAdapter($db) which takes the newly created Zend_Db object, now every Zend_Db_table object can use the Db object you set in your configuration.
  5. Return the newly created object
  6. Go back to 3.
  7. Router, Controller, Layout, View, etc.

This "behavior" is recent, it's why you may found some old tutorial which shows you how to bootstrap your Zend_Db object manually, sometimes, it's just to show you how Zend_Db works.

like image 110
Boris Guéry Avatar answered Aug 15 '26 00:08

Boris Guéry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!