简体   繁体   English

为什么Zend Framework在where子句中添加括号?

[英]Why Zend Framework is adding parentheses in where clause?

I have the following query: 我有以下查询:

$tagCordQuery = $this->freqDb->select()
                    ->from("rr_amplifiers", "*")
                    ->join("amplifiers_coordinate", "amplifiers_coordinate.name = TRIM(TRAILING '0' FROM  rr_amplifiers.name)", array())
                    ->where("amplifiers_coordinate.name IN(?)", $apsName);

Where $apsName it's an array. $ apsName是一个数组。

The problem is when this array has only one element the query had extra parenthesis like this: 问题是,当此数组只有一个元素时,查询将具有额外的括号,例如:

SELECT `rr_amplifiers`.* FROM `rr_amplifiers`
 INNER JOIN `amplifiers_coordinate` ON amplifiers_coordinate.name = TRIM(TRAILING '0' FROM  rr_amplifiers.name) WHERE (amplifiers_coordinate.name IN('xpto'))

Why this it's happen? 为什么会这样呢?

It's in case you did something like this: 万一您做了这样的事情:

->where("amplifiers_coordinate.name IN(?) OR something = 1", $apsName);

(ie include an OR condition in the WHERE). (即在WHERE中包含OR条件)。 Without the parentheses, the query wouldn't work as you'd expect. 没有括号,查询将无法正常工作。

Zend Framework allows you to add more than one where statement. Zend Framework允许您添加多个where语句。 Always wrapping the clause in parentheses prevents unintended logic from occuring. 始终将子句括在括号中可防止发生意外的逻辑。

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

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