Master / Slave switch in the Zend Framework application layer

前端 未结 3 1986
忘了有多久
忘了有多久 2021-01-02 18:24

I am writing an application which requires the Master/Slave switch to happen inside the application layer. As it is right now, I instantiate a Zend_Db_Table object on creati

3条回答
  •  囚心锁ツ
    2021-01-02 18:53

    An object of type Zend_Db_Table_Row_Abstract remembers what Table object produced it. But you can change the associated Table before you call save().

    $readDb = Zend_Db::factory(...);  // replica
    $writeDb = Zend_Db::factory(...); // master
    Zend_Db_Table::setDefaultAdapter($readDb);
    
    $myReadTable = new MyTable(); // use default adapter
    $myWriteTable = new MyTable($writeDb);
    
    $row = $myTable->find(1234)->current();
    
    $row->column1 = 'value';
    
    $row->setTable($myWriteTable);
    
    $row->save();
    

提交回复
热议问题