• <tfoot id='kTA53'></tfoot>

    <small id='kTA53'></small><noframes id='kTA53'>

    <i id='kTA53'><tr id='kTA53'><dt id='kTA53'><q id='kTA53'><span id='kTA53'><b id='kTA53'><form id='kTA53'><ins id='kTA53'></ins><ul id='kTA53'></ul><sub id='kTA53'></sub></form><legend id='kTA53'></legend><bdo id='kTA53'><pre id='kTA53'><center id='kTA53'></center></pre></bdo></b><th id='kTA53'></th></span></q></dt></tr></i><div id='kTA53'><tfoot id='kTA53'></tfoot><dl id='kTA53'><fieldset id='kTA53'></fieldset></dl></div>
  • <legend id='kTA53'><style id='kTA53'><dir id='kTA53'><q id='kTA53'></q></dir></style></legend>

        • <bdo id='kTA53'></bdo><ul id='kTA53'></ul>

        Zend Framework应用层的Master/Slave切换

        时间:2023-10-02
          <tbody id='PMidr'></tbody>

        <small id='PMidr'></small><noframes id='PMidr'>

        • <tfoot id='PMidr'></tfoot>
            • <bdo id='PMidr'></bdo><ul id='PMidr'></ul>

                  <legend id='PMidr'><style id='PMidr'><dir id='PMidr'><q id='PMidr'></q></dir></style></legend>

                  <i id='PMidr'><tr id='PMidr'><dt id='PMidr'><q id='PMidr'><span id='PMidr'><b id='PMidr'><form id='PMidr'><ins id='PMidr'></ins><ul id='PMidr'></ul><sub id='PMidr'></sub></form><legend id='PMidr'></legend><bdo id='PMidr'><pre id='PMidr'><center id='PMidr'></center></pre></bdo></b><th id='PMidr'></th></span></q></dt></tr></i><div id='PMidr'><tfoot id='PMidr'></tfoot><dl id='PMidr'><fieldset id='PMidr'></fieldset></dl></div>

                1. 本文介绍了Zend Framework应用层的Master/Slave切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在编写一个应用程序,它需要在应用程序层内进行主/从切换.就像现在一样,我在创建映射器时实例化一个 Zend_Db_Table 对象,然后 setDefaultAdapter 到从属设备.

                  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 creation of the mapper, and then setDefaultAdapter to the slave.

                  现在在基本映射器类中,我有以下方法:

                  Now inside of the base mapper classe, I have the following method:

                  public function useWriteAdapter()
                  {
                      if(Zend_Db_Table_Abstract::getDefaultAdapter() != $this->_writeDb)
                      {
                          Zend_Db_Table_Abstract::setDefaultAdapter($this->_writeDb);
                          $this->_tableGateway = new Zend_Db_Table($this->_tableName);
                      }
                  }
                  

                  我需要对此进行完整性检查.我不认为开销太大,我只是怀疑一定有更好的方法.

                  I need a sanity check on this. I don't think the overhead is too much, I just suspect there must be a better way.

                  推荐答案

                  Zend_Db_Table_Row_Abstract 类型的对象会记住产生它的 Table 对象.但是您可以在调用 save() 之前更改关联的 Table.

                  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();
                  

                  这篇关于Zend Framework应用层的Master/Slave切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Zend_Form 中,如何避免 Zend_Validate_Email 产生多个 下一篇:使用 Zend Framework 和 PHP 发送电子邮件

                  相关文章

                  最新文章

                2. <i id='ojFLK'><tr id='ojFLK'><dt id='ojFLK'><q id='ojFLK'><span id='ojFLK'><b id='ojFLK'><form id='ojFLK'><ins id='ojFLK'></ins><ul id='ojFLK'></ul><sub id='ojFLK'></sub></form><legend id='ojFLK'></legend><bdo id='ojFLK'><pre id='ojFLK'><center id='ojFLK'></center></pre></bdo></b><th id='ojFLK'></th></span></q></dt></tr></i><div id='ojFLK'><tfoot id='ojFLK'></tfoot><dl id='ojFLK'><fieldset id='ojFLK'></fieldset></dl></div>

                  <small id='ojFLK'></small><noframes id='ojFLK'>

                3. <legend id='ojFLK'><style id='ojFLK'><dir id='ojFLK'><q id='ojFLK'></q></dir></style></legend>
                4. <tfoot id='ojFLK'></tfoot>

                        <bdo id='ojFLK'></bdo><ul id='ojFLK'></ul>