Jump to content

Editing application.ini within the bootstrap


Ravani

Recommended Posts

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!

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'));
    }

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.