3

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?

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

ah right, so im assuming that anything under resource.db, relates to an instance of the zend_db class?
yup!! If you check in the Zend/Application/Resource folder you'll see all the resource classes that come with Zend. When you see resources.* it'll go to this folder and look for the corresponding resource class and feed it the parameters it got from the .ini file. The class uses these to then create the actual object you'll use later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.