views:

107

answers:

2

Are Zend_Db_Select's where() method, when including the optional value to quite into, and Zend_Db_Adapte's quoteInto() methods basically the same as far as escaping SQL?

In other words, are these two pieces of quote identical and equally secure?

$select->where($this->getAdapter()->quoteInto('id = ?', 3));

$select->where(id = ?, 3);

Thanks!

+1  A: 

Zend_Db_Select::_where() is using Zend_Db_Abstract::quoteInto() to quote the value(s) you specify as the second parameter in Zend_Db_Select::where() when assembling the sql string.

From line 983 of Zend_Db_Select:

/**
 * Internal function for creating the where clause
 *
 * @param string   $condition
 * @param mixed    $value  optional
 * @param string   $type   optional
 * @param boolean  $bool  true = AND, false = OR
 * @return string  clause
 */
protected function _where($condition, $value = null, $type = null, $bool = true)
{
    if (count($this->_parts[self::UNION])) {
        require_once 'Zend/Db/Select/Exception.php';
        throw new Zend_Db_Select_Exception("Invalid use of where clause with " . self::SQL_UNION);
    }

    if ($value !== null) {
        $condition = $this->_adapter->quoteInto($condition, $value, $type);
    }

    $cond = "";
    if ($this->_parts[self::WHERE]) {
        if ($bool === true) {
            $cond = self::SQL_AND . ' ';
        } else {
            $cond = self::SQL_OR . ' ';
        }
    }

    return $cond . "($condition)";
}
Noah Goodrich
Thank you!! I should have thought to look at the source declaration.
Chris
A: 

As I understand it where does this already so specifying it would be redundant.

gaoshan88
Annnnnddd it looks like I should load new answers before hitting Add next time.
gaoshan88