使用Zend中的Alias创建一个sql where condition

时间:2012-07-18 04:30:42

标签: php sql zend-framework

我正在使用zend而且我被困在创建别名的地方条件:

示例代码:

$select = $db->select()
             ->from(array('p' => 'products'), 'p.product_id')
             ->columns('product_name', 'p')
             ->where('p = ?', 'value');
             // Alternatively use columns('p.product_name')

修订代码

$select = $db->select()
             ->from(array('p' => 'products'), 'p.product_id')
             ->columns(array('x' => new Zend_Db_Expr('(SELECT...)'                    
        )))
             ->where('x = ?', 'value');
             // Alternatively use columns('p.product_name')

我为x

创建一个条件

这会产生错误。谁能告诉我我错过了什么?

1 个答案:

答案 0 :(得分:1)

您的格式似乎有误。

我认为在你的情况下它应该如下,

$select = $db->select()
         ->from(array('p' => 'products'))
         ->columns('product_name')
         ->where('p.id = ?', 'value');

参考:Zend Db Select