【问题标题】:Zend Framework Cardinality violation: 1241 Operand should contain 1 column(s)Zend Framework 基数违规:1241 操作数应包含 1 列
【发布时间】:2010-12-04 23:02:41
【问题描述】:

我有一个 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 列”

有什么帮助吗?

【问题讨论】:

  • 您是否尝试过直接通过 phpMyAdmin 或 sql 提示符运行查询?那么它肯定会返回您所期望的吗?
  • 与问题无关:您忘记将 $months 初始化为数组

标签: php mysql zend-framework


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    您是否错过了流程中的某个阶段?查询语句行如下:

        /**
     * 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;
     }
    }
    

    【讨论】:

      【解决方案3】:

      我和你一样工作,但最后我通过使用 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);
      

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

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-06-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-21
          • 2013-10-04
          • 1970-01-01
          相关资源
          最近更新 更多