【问题标题】:When i use my Zend_Db_Table_Abstract with select and join, fetchAll return me one row当我将 Zend_Db_Table_Abstract 与 select 和 join 一起使用时,fetchAll 返回一行
【发布时间】:2011-12-03 18:46:03
【问题描述】:

我的课程有问题(由 Zend_Db_Table_Abstract 扩展),它每次只返回一行,并带有一个连接和选择....

我在互联网上搜索,但我没有找到关于这个“错误”的任何内容!

class Api_Model_News extends Zend_Db_Table_Abstract
{
protected $_name = 'news';
protected $_primary = 'news_id';

protected $select;

public function init()
{
  $this->select = $this->select();
}

public function setTimestamp($timestamp)
{
  $this->select
    ->where('news_timestamp >= ?', $timestamp);
  return $this;
}
public function setCategory($id_category)
{
  $this->select
    ->where('bsn_id_category = ?', $id_category);
  return $this;
}

public function getNews()
{
  $this->select
    ->from('news')
    ->joinLeft('business', 'news_id = bsn_id', array());
  $data = $this->fetchAll($this->select);
  return $data->toArray();
}

}

在另一个函数中:

$news = new Api_Model_News();                    

if ($id_category != NULL)
  $news->setCategory($id_category);

if ($last_sync != NULL)
  $news->setTimestamp($last_sync);

return $news->getNews();
  • 当我设置id_category 而不是last_sync => 只有一行
  • 当我设置last_sync 而不是id_category => 多行
  • 当我设置last_syncid_category => 只有一行

为什么?我想这是因为我在select 中使用了bsn_id_category,但我不明白....

【问题讨论】:

    标签: php mysql database zend-framework join


    【解决方案1】:

    在最后一个答案的基础上,试试这个:

     $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
           ->setIntegrityCheck(false)
           ->joinLeft('business', 'news_id = bsn_id', array());
    

    【讨论】:

      【解决方案2】:

      尝试将完整性检查设置为 false 为"Setting this flag to false skips the checks for table joins, allowing 'hybrid' table rows to be created"

        $this->select
             ->setIntegrityCheck(false)
             ->joinLeft('business', 'news_id = bsn_id', array());
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-02
        • 2020-07-10
        • 1970-01-01
        相关资源
        最近更新 更多