Propel:SQL中OR的等价物是什么?

时间:2010-09-30 14:40:04

标签: criteria propel

创建OR的方法是什么?

我的意思是:我知道要创建这个SQL子句:

SELECT * FROM author WHERE author.FIRST_NAME = 'Karl' AND author.LAST_NAME <> 'Marx';

我应该这样做:

<?php
$c = new Criteria();
$c->add(AuthorPeer::FIRST_NAME, "Karl");
$c->add(AuthorPeer::LAST_NAME, "Marx", Criteria::NOT_EQUAL);
$authors = AuthorPeer::doSelect($c);

但如果我想创建:

SELECT * FROM author WHERE author.FIRST_NAME = 'Karl' OR author.LAST_NAME <> 'Marx';

我该怎么办?

此致

哈维

2 个答案:

答案 0 :(得分:3)

$c = new Criteria();  
$cton1 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Karl");  
$cton2 = $c->getNewCriterion(AuthorPeer::LAST_NAME, "Marx", Criteria::NOT_EQUAL);  
$cton1->addOr($cton2);  
$c->add($cton1);  

答案 1 :(得分:0)