Author Topic: Editing application.ini within the bootstrap  (Read 553 times)

0 Members and 1 Guest are viewing this topic.

Offline RavaniTopic starter

  • Irregular
  • Posts: 19
    • View Profile
Editing application.ini within the bootstrap
« on: November 11, 2010, 07:48:27 AM »
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
Code: [Select]
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!

Offline RavaniTopic starter

  • Irregular
  • Posts: 19
    • View Profile
Re: Editing application.ini within the bootstrap
« Reply #1 on: November 12, 2010, 05:29:29 AM »
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'));
    }