使用Zend中的Alias创建sqlwhere条件


Create a sql where condition using Alias in Zend

我使用的是zend,在别名上创建where条件时遇到了麻烦

样本代码:

$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 创建一个条件

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

您的格式似乎有误。

我认为在你的情况下应该是这样,

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

参考:Zend Db选择