简体   繁体   English

Zend Framework选择where子句占位符会减慢过程

[英]Zend Framework select where clause placeholder slows process

I'm using Zend Framework 1.12.3, and I've noticed that using the '?' 我正在使用Zend Framework 1.12.3,并且已经注意到使用'?' placeholder in the where clause slows down the process: where子句中的占位符会减慢该过程:

$query = $this->getDbTable()->select()
    ->from($this->getDbTable(), array('id'))
    ->where('id = ?', $id);

Is considerably slower than: 慢于:

$query = $this->getDbTable()->select()
    ->from($this->getDbTable(), array('id'))
    ->where('id =' . $id);

Here are the getDbTable and setDbTable methods, while $_dbTable is a protected property: 这是getDbTable和setDbTable方法,而$ _dbTable是受保护的属性:

public function setDbTable($dbTable)
{
    if (is_string($dbTable)) {
        $dbTable = new $dbTable();
    }
    if (!$dbTable instanceof Zend_Db_Table_Abstract) {
        throw new Exception('Invalid table data gateway provided');
    }
    $this->_dbTable = $dbTable;
    return $this;
}

public function getDbTable()
{
    if (null === $this->_dbTable) {
        $this->setDbTable('V1_Model_DbTable_Users');
    }
    return $this->_dbTable;
}

And V1_Model_DbTable_Users class: 和V1_Model_DbTable_Users类:

class V1_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
    protected $_name = 'users'; 
}

Has anyone encountered the same issue? 有没有人遇到过同样的问题? Do you have any solutions? 你有什么解决方案? Thanks 谢谢

请记住,您的第一个示例正在使用功能对输入进行转义,第二个示例与使用原始SQL编写相同。

You should not consider something slow until you have this behavior. 在出现这种情况之前,您不应该考虑慢一些。 This seems to me an opinion. 在我看来,这是一种意见。 For the time difference matters, you must be a problem in its architecture levels above that. 对于时差的问题,您必须在高于该级别的体系结构级别上遇到问题。 Many people spend time trying to find a problem where it does not exist as should improve your own code. 许多人花时间尝试查找不存在的问题,这应该改进您自己的代码。

Do not take it so seriously so. 不要那么认真地对待它。 It's just something you should consider as constructive. 这只是您应该考虑的建设性内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM