Jump to content

Editing application.ini within the bootstrap


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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.