bah*_*100 0 sql doctrine symfony1 dql symfony-1.4
我尝试生成自定义查询(我正在为网站开发搜索引擎).
这是要翻译的查询:
SELECT * FROM `offre_habitation`
WHERE `id_type_offre` = 2
AND `id_nature_offre` = 1
AND (`nb_pieces` = 2 or `nb_pieces` = 1 or `nb_pieces` = 3 or `nb_pieces` = 4)
AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3)
AND `surface_habitable` > 90
AND `prix` > 700
Run Code Online (Sandbox Code Playgroud)
请问你能帮帮我吗 ?
没有经过测试,但这样的事情应该可以解决问题:
$q = Doctrine_Query::create()
->select('o.*')
->from('offre_habitation o')
->where('o.id_type_offre = ?', 2)
->andWhere('o.id_nature_offre = ?', 1)
->andWhereIn('o.nb_pieces', array(1, 2, 3, 4))
->andWhereIn('o.id_secteur', array(1, 2, 3))
->andWhere('o.surface_habitable > ?', 90)
->andWhere('o.prix > ?', 700);
// Test:
echo $q->getSqlQuery();
Run Code Online (Sandbox Code Playgroud)
......这利用了这样一个事实,例如:
AND (`id_secteur`=1 OR `id_secteur` = 2 or id_secteur = 3)
Run Code Online (Sandbox Code Playgroud)
...是相同的:
AND `id_secteur` IN (1, 2, 3)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
190 次 |
| 最近记录: |