0

我无法将以下查询转换为 Zend_Db:

SELECT `mfaq`.* FROM `m_faq` AS `mfaq`
WHERE (mfaq.delete_flg <> 'D' OR mfaq.delete_flg IS NULL)
AND ((mfaq.title like '%$title%')
OR (mfaq.title like '%$title%')
AND (mfaq.title like '%$title%') 
OR (mfaq.title like '%$title%'))
ORDER BY `create_date` DESC 

一些帮助???

4

1 回答 1

1

首先,您需要创建 dbtable 模型:

class Application_Model_DbTable_Mfaq extends Zend_Db_Table_Abstract
{
    protected $_name = 'm_faq';
}

然后按如下方式使用它:

$table = new Application_Model_DbTable_Mfaq();

$select = $table->getAdapter()->select()
            ->from(array('mfaq'=>$table->info(Zend_Db_Table::NAME)))
            ->where("( mfaq.delete_flg <> 'D'")
            ->orWhere("mfaq.delete_flg IS NULL )")
            ->where("( mfaq.title like ?", "%$title%")
            ->orWhere("mfaq.title like ? ", "%$title%")
            ->where(" mfaq.title like ?", "%$title%")
            ->orWhere("mfaq.title like ? )", "%$title%")
            ->order("create_date DESC");

// echo $select; // shows your sql
$results = $select->query()->fetchAll();

我希望,您考虑到 AND 比 OR 具有更高的优先级。

于 2013-01-14T18:51:25.457 回答