如何将多个参数传递给Zend_Db_Select?

时间:2013-12-30 08:32:06

标签: php sql zend-framework zend-db

我是ZF初学者,我无法通过Google搜索找到答案。 我有类似的东西:

$query->where('sc.year BETWEEN ? AND ?', array($startYear, $endYear));

如您所见,我尝试将2个参数作为数组传递(请参阅https://stackoverflow.com/a/3305202/2995868)。但它不起作用。我做了一个简单的测试:

$query->where("sc.year BETWEEN ? AND ?",array(1,2))
->where("sc.week BETWEEN IF(year = ?, ?, 1) AND IF(year = ?, ?,53)",array(3,4,5,6));

我希望在原始SQL中看到的内容:

...WHERE (sc.year BETWEEN 1 AND 2) AND (sc.week BETWEEN IF(year = 3, 4, 1) AND IF(year = 5, 6, 53))

我真正看到的是:

...WHERE (sc.year BETWEEN 1, 2 AND 1, 2) AND (sc.week BETWEEN IF(year = 3, 4, 5, 6, 3, 4, 5, 6, 1) AND IF(year = 3, 4, 5, 6, 3, 4, 5, 6, 53)) 

因此ZF只是将数组转换为字符串并将其插入,就像单个参数一样。

我也尝试使用原生PHP风格的东西:

$query->where('sc.year BETWEEN ? AND ?', $startYear, $endYear);

它仍然不起作用。

我知道,我可以使用像sprintf这样的字符串函数,但我想了解如何以正确的方式通过Zend_Db传递多个参数。

0 个答案:

没有答案