MasterSlaveFeature 操作方法 [英] MasterSlaveFeature How-To

查看:34
本文介绍了MasterSlaveFeature 操作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用 AbstractTableGateway 拥有我的数据库模型,并且我所有的选择/插入/更新/删除查询都运行良好.但是现在我想添加 MasterSlaveFeature 并且我对如何执行此操作感到有些困惑.文档并没有给出一个很好的例子:

I currently have my Db Models using AbstractTableGateway and all my select/insert/update/delete queries are working just fine. But now I would like to add the MasterSlaveFeature and I'm a bit confused on how to do this. The documentation doesn't exactly give a good example:

http://zf2.readthedocs.org/en/latest/modules/zend.db.table-gateway.html#tablegateway-features

我目前有这个设置:

namespace Login\Model;

use Zend\Db\TableGateway\Feature\MasterSlaveFeature;
use Zend\Db\TableGateway\Feature\FeatureSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Expression;

class Passport extends AbstractTableGateway
{
public function __construct($adapter, $slave)
{
    $this->table = 'passport';

    $this->adapter = $adapter;

    $this->featureSet = new FeatureSet();
    $this->featureSet->addFeature(new MasterSlaveFeature($slave));

    $this->initialize();
}

public function Profile($employeeid)
{
    $result = $this->select(function (Select $select) use ($employeeid) {
        $select
            ->columns(array(
                'count' => new Expression('COUNT(*)'),
                'employeeid',
                'passwd',
                'group',
                'name',
                'status',
                'timezone',
                'timeformat',
                'locale',
                'max_search'
            ))
            ->where($this->adapter->getPlatform()->quoteIdentifier('employeeid') . ' = ' . $this->adapter->getPlatform()->quoteValue($employeeid))
            ->limit(1);
    });

    return $result->current();
}

}

我传递了两个适配器 $adapter 和 $slave,每个都有相同的表,除了一个是空的,另一个实际上有数据.根据文档,我所拥有的应该可以工作,但我觉得我在这里遗漏了一些东西,但不知道是什么.

I am passing two Adapters $adapter and $slave, each have the same Tables, except one is empty and the other actually has data. Based on the documentation what I have should work, but I feel like I am missing something here, but don't know what.

$adapter 是拥有数据的主数据库$slave 是没有数据的从库

The $adapter is the master database which has the data The $slave is the slave database which has no data

我希望我的 SELECTS 从 $slave(目前没有数据)获取数据,而 Insert/Update/Delete 应该转到 $adapter.

I would like my SELECTS to take the data from the $slave (which currently has no data) and Insert/Update/Delete should go to the $adapter.

有人可以帮我解决这个问题吗?谢谢

Can someone help me figure this out? Thank you

推荐答案

更新:从 ZF 2.0.5 开始,存在一个错误.配置正确.

UPDATE: As of ZF 2.0.5 there is a bug. The configuration is correct.

更新:看起来这应该在 2.1 版本中解决

UPDATE: Looks like this should be resolved in the 2.1 release

更新:我现在可以确认这已解决并在 2.0.7 和 2.1 中工作

UPDATE: I can now confirm this is resolved and working in 2.0.7 and 2.1

这篇关于MasterSlaveFeature 操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆