Ravani Posted November 11, 2010 Share Posted November 11, 2010 Hi everyone, I'm working on a Zend Framework project and I need to use two databases. I was wondering if it is possible to change the database configuration of application.ini within the bootstrap. This is what I am using at the moment: Bootstrap public function _initDbRegistry() { $this->bootstrap('multidb'); $multidb = $this->getPluginResource('multidb'); Zend_Registry::set('db_local', $multidb->getDb('local')); Zend_Registry::set('db_remote', $multidb->getDb('remote')); } application.ini resources.multidb.local.adapter = pdo_mysql resources.multidb.local.host = localhost resources.multidb.local.username = root resources.multidb.local.password = resources.multidb.local.dbname = system resources.multidb.local.default = true resources.multidb.remote.adapter = pdo_mysql resources.multidb.remote.host = localhost resources.multidb.remote.username = root resources.multidb.remote.password = resources.multidb.remote.dbname = customer resources.multidb.remote.default = false Ok the problem is that I want to change the dbname of remote. Is there any way of doing that? Is it possible to add the remote db configuration within the bootstrap? Why I want this is because the dbname needs to be variable. Anyone here with a solution?? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/218386-editing-applicationini-within-the-bootstrap/ Share on other sites More sharing options...
Ravani Posted November 12, 2010 Author Share Posted November 12, 2010 For those who are interested, the solution was quite simple. I deleted the local db parameters from the ini file and editted my _initDbRegistry function inside the bootstrap into: public function _initDbRegistry() { $this->bootstrap('multidb'); $multidb = $this->getPluginResource('multidb'); $dbName = $this->loadDatabase('customer'); $dbCustomer = array('host' => 'localhost', 'username' => 'root', 'password' => '', 'dbname' => $dbName, 'default' => true,); $dbCustomerAdapter = new Zend_Db_Adapter_Pdo_Mysql($dbCustomer); Zend_Db_Table::setDefaultAdapter($dbCustomerAdapter); Zend_Registry::set('db_local', $dbCustomerAdapter); Zend_Registry::set('db_remote', $multidb->getDb('remote')); } Quote Link to comment https://forums.phpfreaks.com/topic/218386-editing-applicationini-within-the-bootstrap/#findComment-1133380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.