简体   繁体   中英

Zend Framework select where clause placeholder slows process

I'm using Zend Framework 1.12.3, and I've noticed that using the '?' placeholder in the where clause slows down the process:

$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:

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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