将SQL查询转换为Doctrine代码

时间:2011-04-25 10:44:05

标签: mysql doctrine

如何将此SQL查询写入Doctrine 1.2查询?

SELECT * FROM homes 
    WHERE published = 1 
    AND
    (
     LOWER(country) LIKE '$search%' 
     OR 
     LOWER(city) LIKE '$search%'
     OR
     LOWER(area) LIKE '$search%'
    )

修改

这是我的执行查询。上面的例子是一个简化版本。我现在只想要如何将多个WHERE组合在一起

Doctrine_Query::create()
                        ->select('h.*,c.*')
                        ->from('Homes h')
                        ->where('h.published = ?',1)
                        ->addWhere('LOWER(c.printable_name) LIKE ?', $search . "%")
                        ->orWhere('LOWER(h.city) LIKE ?', $search . "%")
                        ->orWhere('LOWER(h.area) LIKE ?', $search. "%")
                        ->orWhere('LOWER(h.name) LIKE ?', $search. "%")

                        ->leftJoin('h.Countries c');

1 个答案:

答案 0 :(得分:0)

确定有效的脚本是:

Doctrine_Query::create()
                        ->select('h.*,c.*')
                        ->from('Homes h')
                        ->where('h.published = ?',1)
                        ->andWhere('LOWER(c.printable_name) LIKE ? OR LOWER(h.city) LIKE ? OR LOWER(h.area) LIKE ? OR LOWER(h.name) LIKE ?', array($search . "%",$search . "%",$search . "%",$search . "%"))
                        ->leftJoin('h.Countries c');

我不知道这是否是最好的写作方式。