1

我正在将此查询应用于以下 D6 查询,但不工作..不知道我在做什么错了....在某些情况下内部连接是否失败

$result = db_select('px_slides','s')
    ->join('node','n','s.vid = n.vid')
    ->fields('s',array('tissue_type','body_site'))
    ->fields('n',array('sticky','title'))
    ->condition('n.status','1','=')
    ->condition('s.cid','126','=')
    ->execute()->fetchObject();

我有drupal 6查询:

    $result = db_query('
  SELECT n.nid, n.vid, n.sticky, n.title, n.created, s.cid, s.ref_id, s.viewurl, s.specimen_type, s.tissue_type, s.body_site, s.test_type, s.algorithm, s.result 
  FROM {px_slides} s INNER JOIN {node} n ON n.vid = s.vid
  WHERE n.status = 1 ')->execute();
4

3 回答 3

7

You need to put your call to ->join() on a separate line altogether, as it doesn't return the query object:

$query = db_select('px_slides','s')  
  ->fields('s',array('tissue_type','body_site'))
  ->fields('n',array('sticky','title'))
  ->condition('n.status','1','=')
  ->condition('s.cid','126','=');

$query->join('node','n','s.vid = n.vid');

$result = $query->execute()->fetchObject();
于 2012-06-07T16:40:59.250 回答
0

尝试这个...

$query = db_select('px_slides', 's');
$query->innerJoin('node,'n','s.vid = n.vid');
$query->fields('s',array('tissue_type','body_site'));
$query->fields('n',array('sticky','title'));
$query->condition('n.status','1');
$query->condition('s.cid','126');
$result= $query->execute()->fetchAll(PDO::FETCH_ASSOC);
于 2014-07-15T09:14:05.410 回答
0

join 方法不会这样链接。您将不得不执行以下操作:

$query = db_select('px_slides','s')
    ->join('node','n','s.vid = n.vid');
$query->fields('s',array('tissue_type','body_site'))
    ->fields('n',array('sticky','title'))
    ->condition('n.status','1','=')
    ->condition('s.cid','126','=');
$result = $query->execute()->fetchObject();

您还可以使用 to string 魔术方法来查看它将执行的查询。

$query->__toString();
于 2012-06-07T15:32:58.277 回答