Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 11:00 AM
Junior Member
 
Join Date: Apr 2008
Posts: 5
Thumbs down Please help, how to connect two database from index.php

Currently I am using one database for my project, but would want to try connect two database at the same time.
I am using the Adapter factory method with a Zend_Config object as below:

// load configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
Zend_Registry::set('config', $config);

// setup database
$db = Zend_Db::factory($config->db->adapter,$config->db->config->toArray());
$db->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Db_Table::setDefaultAdapter($db); //default adapter for Zend_DB_Table extend class
Zend_Registry::set('mydb', $db); //store the adapter for global use

But I can't write my code right to connect two database. Please advice
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-22-2008, 03:31 AM
Junior Member
 
Join Date: May 2008
Posts: 10
Default

You can just instantiate another Zend_Db object.
PHP Code:
$db1 Zend_Db::factory('Pdo_Mysql', array(
    
'host'     => 'onehost',
    
'username' => 'webuser',
    
'password' => 'xxxxxxxx',
    
'dbname'   => 'test'
));

$db2 Zend_Db::factory('Pdo_Mysql', array(
    
'host'     => 'adifferenthost',
    
'username' => 'webuser',
    
'password' => 'xxxxxxxx',
    
'dbname'   => 'test'
)); 

Last edited by jasonw : 05-22-2008 at 03:36 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:26 AM.