【问题标题】:Problems inner join in zend 1.12zend 1.12 的内部连接问题
【发布时间】:2014-05-16 22:35:27
【问题描述】:

我尝试通过以下方式加入但我做不到,我错了吗?使用 zend 1.12

SELECT al.nombre, ar.nombre FROM `album` AS al
INNER JOIN artista AS ar ON al.artista_id = ar.id


$select = $this->select()
         ->from(array('al' => 'album'),
                array('id', 'nombre'))
         ->join(array('ar' => 'artista'),
                'al.artista_id = ar.id');
    $rows = $this->fetchAll($select);


    return $rows;

【问题讨论】:

  • 抱歉,but I can not 是什么意思?您收到错误消息了吗?
  • 抱歉,出现消息:Select query cannot join with another table

标签: php zend-framework frameworks


【解决方案1】:

只需设置integrity check 标志

$select = $this->select()
     ->setIntegrityCheck(false)
     ->from(array('al' => 'album'),
            array('id', 'nombre'))
     ->join(array('ar' => 'artista'),
            'al.artista_id = ar.id');
$rows = $this->fetchAll($select);


return $rows;

希望对你有帮助

【讨论】:

    【解决方案2】:

    问题是,你没有使用正确的对象

    $select = $this->select()
             ->from(array('al' => 'album'),
                    array('id', 'nombre'))
             ->join(array('ar' => 'artista'),
                    'al.artista_id = ar.id');
    
        $rows = $select ->query()->fetchAll();
    
    
        return $rows;
    

    【讨论】:

    • 1- 没有任何解释,我几乎没有注意到你和他的帖子之间的变化! 2- $rows = $select ->fetchAll($select); 不正确。您应该运行 1. $rows = $select->query()->fetchAll(); //或 2. $rows = $this->fetchAll($select); //就像他所做的一样谢谢
    • 没错,忘记了查询()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多