Zend Framework基数违规:1241操作数应包含1列

时间:2009-10-08 11:11:22

标签: php mysql zend-framework

我有一个sql问题,我不知道如何解决它,我尝试过一些事情但是......你知道。所以这是我的疑问:

    /**
 * Returns a list with all the months for the archive
 *
 * @return array
 */
public function Archive()
{
 $q = "SELECT DISTINCT MONTH(`data`) AS `month`,YEAR(`data`) AS `year` FROM `posts` ORDER BY `data` DESC";
 $all = $this->fetchAll($q);
 if (count($all) > 0) {
  foreach ($all as $info) {
$months[] = array('month_name'=>$this->months($info['month']),'year'=>$info['year'],'month'=>$info['month']);
  }
  return $months;
 }else{
  return false;
 }
}

我的错误:

  
    

致命错误:未捕获的异常'Zend_Db_Statement_Exception',消息'SQLSTATE [21000]:基数违规:1241操作数应包含1列

  

任何帮助?

4 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,最后我发现我为列发布了错误的值。我正在为一个列发送2个值。 因此,检查为函数指定的参数值。

答案 1 :(得分:3)

你错过了这个过程中的一个阶段吗?查询语句行如下:

    /**
 * Returns a list with all the months for the archive
 *
 * @return array
 */
public function Archive()
{
 $q = "SELECT DISTINCT MONTH(`data`) AS `month`,YEAR(`data`) AS `year` FROM `posts` ORDER BY `data` DESC";
 $stmt = $db->query($q);
 $all = $stmt->fetchAll(); 
 if (count($all) > 0) {
  foreach ($all as $info) {
$months[] = array('month_name'=>$this->months($info['month']),'year'=>$info['year'],'month'=>$info['month']);
  }
  return $months;
 }else{
  return false;
 }
}

答案 2 :(得分:1)

我和你一样工作,但最后我通过使用Zend_Db_Select对象而不是查询字符串来解决它:

$select =  $this->getDbTable()->select(); // $this->select(); // 
$select->from('gallery', '*');
$select->where('id_category = ?', $id_category);
$select->where('active', 1);

$resultSet = $this->getDbTable()->fetchAll($select);

已编辑:缩进代码标记显示。

答案 3 :(得分:0)

我有同样的问题。看来这是一个Zend Bug。

来源: http://framework.zend.com/issues/browse/ZF-3311