Php 推进;而不是",;查询

Php 推进;而不是",;查询,php,mysql,orm,propel,Php,Mysql,Orm,Propel,我在PHP应用程序中使用了推进ORM 通过阅读文档,我不知道如何提出这种类型的请求: SELECT x FROM table where col1 = 'xxx' and not(col2=1 AND col3=2); 使用纯推进逻辑执行此请求的最干净方式是什么 谢谢您的查询相当于: SELECT x FROM table where col1 = 'xxx' and (col2 != 1 OR col3 != 2); 假设您使用的是propel 2,您应该能够完成您想要的: $result

我在PHP应用程序中使用了推进ORM

通过阅读文档,我不知道如何提出这种类型的请求:

SELECT x FROM table where col1 = 'xxx' and not(col2=1 AND col3=2);
使用纯推进逻辑执行此请求的最干净方式是什么


谢谢

您的查询相当于:

SELECT x FROM table where col1 = 'xxx' and (col2 != 1 OR col3 != 2);
假设您使用的是propel 2,您应该能够完成您想要的:

$result = TableQuery::create()
    ->filterByCol1('xxx')
    ->filterByCol2(1, Criteria:NOT_EQUAL)
    ->_or()
    ->filterByCol3(2, Criteria:NOT_EQUAL)
    ->find();

您的查询相当于:

SELECT x FROM table where col1 = 'xxx' and (col2 != 1 OR col3 != 2);
假设您使用的是propel 2,您应该能够完成您想要的:

$result = TableQuery::create()
    ->filterByCol1('xxx')
    ->filterByCol2(1, Criteria:NOT_EQUAL)
    ->_or()
    ->filterByCol3(2, Criteria:NOT_EQUAL)
    ->find();

您要查找的完整查询应该是:

$books = TableQuery::create()
    ->condition('cond1', 'col1 = ?', 'xxx')
    ->condition('cond2', 'col2 != ?', 1)
    ->condition('cond3', 'col3 != ?', 2)
    ->combine(array('cond2', 'cond3'), 'or', 'cond23')
    ->where(array('cond1', 'cond23'), 'and')
    ->find();
它创造了:

  • 一个cond1条件,其中col1='xxx'
  • cond2条件,其中col2!=一,
  • 一个cond3条件,其中col3!=二,
然后它将cond2和cond3与新的cond23中的or运算符组合,以便

cond23 = cond2 or cond3
并将cond23和cond1与and运算符组合,以便最终查询

where(cond1 and cond23)

您要查找的完整查询应该是:

$books = TableQuery::create()
    ->condition('cond1', 'col1 = ?', 'xxx')
    ->condition('cond2', 'col2 != ?', 1)
    ->condition('cond3', 'col3 != ?', 2)
    ->combine(array('cond2', 'cond3'), 'or', 'cond23')
    ->where(array('cond1', 'cond23'), 'and')
    ->find();
它创造了:

  • 一个cond1条件,其中col1='xxx'
  • cond2条件,其中col2!=一,
  • 一个cond3条件,其中col3!=二,
然后它将cond2和cond3与新的cond23中的or运算符组合,以便

cond23 = cond2 or cond3
并将cond23和cond1与and运算符组合,以便最终查询

where(cond1 and cond23)

逻辑上,这相当于col1='xxx'和(col2!=1或col3!=2)。。。这似乎更容易用
->组合(数组('cond2','cond3'),'或',…)
表示,然后将其与条件1,
组合。我再也帮不上忙了,因为我是DBA。。。所以怪物是我的死敌。谢谢你的回答。谢谢你的回答。我之前尝试过这种方法,使用combine(),但我遇到了一个奇怪的行为:->条件('cond1','x!=?',1)->条件('cond2','y!=?',2)->条件('cond3','z!=?',3)->组合(数组('cond1','cond2','cond3'),'或''cond12')结果:选择。。。(x!=1或y!=2)或z!=3)这其实不是同一件事。呜呜,有一个愚蠢的时刻,我想,事实上,这完全是同一件事……逻辑上,这相当于col1='xxx'和(col2!=1或col3!=2)。。。这似乎更容易用
->组合(数组('cond2','cond3'),'或',…)
表示,然后将其与条件1,
组合。我再也帮不上忙了,因为我是DBA。。。所以怪物是我的死敌。谢谢你的回答。谢谢你的回答。我之前尝试过这种方法,使用combine(),但我遇到了一个奇怪的行为:->条件('cond1','x!=?',1)->条件('cond2','y!=?',2)->条件('cond3','z!=?',3)->组合(数组('cond1','cond2','cond3'),'或''cond12')结果:选择。。。(x!=1或y!=2)或z!=3)这其实不是一回事。呜呜,有一个愚蠢的时刻,我想,事实上,这完全是一回事。。。