richzilla
richzilla

Reputation: 42062

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?

Upvotes: 3

Views: 468

Answers (1)

Boris Guéry
Boris Guéry

Reputation: 47614

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.

Upvotes: 8

Related Questions