1

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!

Chris
  • 11
  • 2

2 Answers2

1

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
  • 24,875
  • 14
  • 66
  • 96
0

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

rg88
  • 20,742
  • 18
  • 76
  • 110