Init Zend Framework DB


/ Published in: PHP
Save to your folder(s)

Goes in /Application/Bootstrap.php


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.