Search code examples
phpzend-frameworkobjectinitializationzend-db-select

How to initiate Zend_Db_Select object?


Hey guys, I'm having truble figuring this out: how do I initiate a zend_Db_Select object with the resources from my application.ini?

$db = Zend_Registry::get('db'); $select = $db->select();

But it's not working, I guess I have to add db to the registry first or something? Not sure how to do that though. Any ideas? I have my database details in application.ini


Solution

  • You can only get objects from the registry which have been set before. So

    $db = Zend_Registry::get('db'); $select = $db->select();

    will return null, not an db adapter. You can initialize the adapter via the bootstrap. Read:

    http://framework.zend.com/manual/en/zend.application.theory-of-operation.html hxxp://www.zendframework.com/manual/en/zend.application.available-resources.html

    For the initialization of the db adapter (which is done by the bootstrap resource plugin for you) read:

    hxxp://framework.zend.com/manual/en/zend.db.adapter.html

    I wouldn't recommend using the registry at all, it is better to get the resources from the bootstrap.