Zend_Db_Select 的 where() 方法,当包含可选值时,与 Zend_Db_Adapte 的 quoteInto() 方法在转义 SQL 方面基本相同吗?
换句话说,这两条报价是否相同且同样安全?
$select->where($this->getAdapter()->quoteInto('id = ?', 3));
$select->where(id = ?, 3);
谢谢!
Zend_Db_Select 的 where() 方法,当包含可选值时,与 Zend_Db_Adapte 的 quoteInto() 方法在转义 SQL 方面基本相同吗?
换句话说,这两条报价是否相同且同样安全?
$select->where($this->getAdapter()->quoteInto('id = ?', 3));
$select->where(id = ?, 3);
谢谢!
Zend_Db_Select::_where() 在组装 sql 字符串时使用 Zend_Db_Abstract::quoteInto() 来引用您在 Zend_Db_Select::where() 中指定为第二个参数的值。
从 Zend_Db_Select 的第 983 行开始:
/**
* 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)";
}
据我了解,这已经在哪里指定它是多余的。