7

看起来Zend_Db_Select's on 子句中没有任何参数替换。

我不能只做类似的事情,这很烦人:

$select->joinLeft('st_line_item','st_line_item.order_id = st_order.id and st_line_item.status = ?')

那么在流畅的界面中工作的惯用替代方案是什么?我可以做一些事情,比如在外面准备 join 子句,但这不是重点。

4

2 回答 2

11

这应该有效:

$select->joinLeft(
    'st_line_item',
    $this->_db->quoteInto(
        'st_line_item.order_id = st_order.id and st_line_item.status = ?', 
        $param
    )
)

基本上,只要您想转义一个 Zend_Db_* 方法不能自动执行的变量,您只需使用 Zend_Db::quoteInto() 来完成这项工作。

于 2010-02-02T20:19:03.687 回答
1

This is how I always do it, it's not a work of art but it gets the job done:

$param = $db->quote($param);
$select->joinLeft(
    'st_line_item',
    'st_line_item.order_id = st_order.id and st_line_item.status = ' . $param
);
于 2010-02-02T07:16:32.890 回答