Php 哪里是非原则

Php 哪里是非原则,php,sql,symfony1,doctrine,symfony-1.4,Php,Sql,Symfony1,Doctrine,Symfony 1.4,如果表first中没有第一个id,如何从表first中获取所有数据?方法一(类似于您的示例代码): 在单个复合查询中获得相同结果的另一种方法: // Retrieve ONLY the id, and use hydration mode that produces a simple array of results. $first_ids = Doctrine_Query::create() ->select('f.id') ->from('First f') ->

如果表first中没有第一个id,如何从表first中获取所有数据?

方法一(类似于您的示例代码):

在单个复合查询中获得相同结果的另一种方法:

// Retrieve ONLY the id, and use hydration mode that produces a simple array of results.
$first_ids = Doctrine_Query::create()
  ->select('f.id')
  ->from('First f')
  ->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);

$two = Doctrine_Query::create()
  ->from('Second s')
  ->whereNotIn('first_id', $first_ids);
return $two->execute();

代码中的问题包括:第一个查询返回一个条令集合(如条令记录列表),这不是一个可以输入到第二个查询中的数组。另外,您需要的方法是“whereNotIn()”而不是“whereInNot()”。在我的回答中,我提供了两个示例,说明如何编写代码,这取决于您是否确实需要知道第一个\u id。
// Retrieve ONLY the id, and use hydration mode that produces a simple array of results.
$first_ids = Doctrine_Query::create()
  ->select('f.id')
  ->from('First f')
  ->execute(array(), Doctrine_Core::HYDRATE_SINGLE_SCALAR);

$two = Doctrine_Query::create()
  ->from('Second s')
  ->whereNotIn('first_id', $first_ids);
return $two->execute();
$two = Doctrine_Query::create()
  ->from('Second s')
  ->where('first_id NOT IN (SELECT id FROM First)');
return $two->execute();