0

I have already found this question: ZEND FW : Joining two tables from different databases. But the answers below did not solve the topic.

I used Zend Framework(1.8.3) in my project. And it used to use only one database. Recently there is a change on the database. Now I should connect to two databases when users open my website. There are some left join operations in my code then. The similar code is as follow:

...

public static function getAdapter () {
    $db = Zend_Db::factory( 'PDO_MYSQL', $GLOBALS['g_config']['db']['params'] );
    return $db;
}

---------------------------------------------------------------------------------
private $_db;

...

public function __construct () {
    $this->_db = Model_DbTable_Abstract::getAdapter();
}

public function getUnits () {
    $objSelect = $this->_db->select();
    $objSelect->from( 'table_unit', array('*') );
    $objSelect->joinLeft( 'user',
                          'table_unit.ucid=user.ucid',
                          array('user_name') );
    $objSelect->joinLeft( 'table_position', 
                          'table_unit.position_id=table_position.id',
                          array('position_name' => 'name') );
    $objSelect->where( 'table_unit.status=?', 'SOMETHING' );
    $arrRes = $this->_db->fetchAll($objSelect);
    return $arrRes;
}

And now the table 'user' is in another database. How can I do the 'joinLeft' operation to achieve the same result?

Community
  • 1
  • 1
chestnut
  • 252
  • 2
  • 16

0 Answers0