将 FORCE INDEX 与 zend 结合使用

发布于 2024-12-05 02:15:47 字数 526 浏览 0 评论 0原文

我尝试找到如何将以下 MySQL 查询转换为 Zend Db Table Select:

SELECT ColA,ColB,ColC
FROM MyTable
FORCE INDEX(ColA,ColB)
WHERE ColA = 'val0002'
AND ColB = 'val0045'

我尝试使用类似这样的内容:

$select = $dbTable->select()
            ->from('MyTable',array('ColA','ColB')
            ->forceIndex(array('ColA','ColB'))
            ->where("ColA = 'val0002'")
            ->where("ColB = 'val0045'");

我在论坛中找到了“forceIndex(array('ColA','ColB'))”,但它没有工作:(

谢谢你帮助我:)

I try to find how to translate the following MySQL query into Zend Db Table Select:

SELECT ColA,ColB,ColC
FROM MyTable
FORCE INDEX(ColA,ColB)
WHERE ColA = 'val0002'
AND ColB = 'val0045'

i try to use something like this:

$select = $dbTable->select()
            ->from('MyTable',array('ColA','ColB')
            ->forceIndex(array('ColA','ColB'))
            ->where("ColA = 'val0002'")
            ->where("ColB = 'val0045'");

I found " forceIndex(array('ColA','ColB')) " in a forum, but it does not work :(

and thank you for helping me :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚殇 2024-12-12 02:15:48

我认为 Zend_Db_Select 还不支持它。这里似乎有一个关于它的改进请求: http://framework.zend.com/ issues/browse/ZF-7570

(报告评论包含一些可能对您有用的代码链接)。

希望有帮助,

I think Zend_Db_Select doesn't support it yet. There seems to be an improvement request about it here: http://framework.zend.com/issues/browse/ZF-7570

(The report comments contain some links to code that could be useful to you).

Hope that helps,

肩上的翅膀 2024-12-12 02:15:48

这是一个可以帮助对该问题感兴趣的解决方案:
http://pastie.org/1354770

我们可以将以下两个方法添加到 zend 类“Zend_Db”中。我希望它能帮助你,就像它帮助我一样(但部分)。

/**
 * Specify index to use
 *
 * @return Zend_Db_Select
 */
public function useIndex($index)
{
    if(empty($this->_parts[self::FORCE_INDEX])) {
        if(!is_array($index)) {
            $index = array($index);
        }
        $this->_parts[self::USE_INDEX] = $index;
        return $this;
    } else {
        throw new Zend_Db_Select_Exception("Cannot use 'USE INDEX' in the same query as 'FORCE INDEX'");
    }
}

/**
 * Force index to use
 *
 * @return Zend_Db_Select
 */
public function forceIndex($index)
{
    if(empty($this->_parts[self::USE_INDEX])) {
        if(!is_array($index)) {
            $index = array($index);
        }
        $this->_parts[self::FORCE_INDEX] = $index;
        return $this;
    } else {
        throw new Zend_Db_Select_Exception("Cannot use 'FORCE INDEX' in the same query as 'USE INDEX'");
    }
}

here's a solution that can help interested by the problem :
http://pastie.org/1354770

we can add the following two methods to the zend class "Zend_Db". I hope it will help you as it helped me (but partially).

/**
 * Specify index to use
 *
 * @return Zend_Db_Select
 */
public function useIndex($index)
{
    if(empty($this->_parts[self::FORCE_INDEX])) {
        if(!is_array($index)) {
            $index = array($index);
        }
        $this->_parts[self::USE_INDEX] = $index;
        return $this;
    } else {
        throw new Zend_Db_Select_Exception("Cannot use 'USE INDEX' in the same query as 'FORCE INDEX'");
    }
}

/**
 * Force index to use
 *
 * @return Zend_Db_Select
 */
public function forceIndex($index)
{
    if(empty($this->_parts[self::USE_INDEX])) {
        if(!is_array($index)) {
            $index = array($index);
        }
        $this->_parts[self::FORCE_INDEX] = $index;
        return $this;
    } else {
        throw new Zend_Db_Select_Exception("Cannot use 'FORCE INDEX' in the same query as 'USE INDEX'");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文