Posted By

Rhoxus on 10/19/10


Tagged

db initialize Framework ZF zend


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

postNuKe
foltrabix


Init Zend Framework DB


 / Published in: PHP
 

Goes in /Application/Bootstrap.php

  1. protected function _initDb()
  2. {
  3. /*
  4. Assuming your config contains the following:
  5.  
  6. database.adapter = [Adapter type], for MySQL = Pdo_Mysql
  7. database.host = [Host URL]
  8. database.username = [Username]
  9. database.password = [Password]
  10. database.dbname = [DBName]
  11. */
  12.  
  13. $config = Zend_Registry::get('config');
  14.  
  15. $db = Zend_Db::factory($config->database->adapter, array(
  16. 'host' => $config->database->host,
  17. 'username' => $config->database->username,
  18. 'password' => $config->database->password,
  19. 'dbname' => $config->database->dbname
  20. ));
  21.  
  22. Zend_Db_Table_Abstract::setDefaultAdapter($db);
  23. Zend_Registry::set('db', $db);

Report this snippet  

You need to login to post a comment.