简体   繁体   中英

Zend Framework Cardinality violation: 1241 Operand should contain 1 column(s)

I have a sql problem and i don't know how to fix it, I have tried a few things but..you know.So here is my query:

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

And my Error:

Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)' in

Any help?

I had the same problem, finally I found that I was posting wrong value for a column. I was sending 2 values for a column. So, Check value of your parameters that are given to your function.

Are you missing out a stage in the process? The query statement line as below:

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

I was working just like you but finally I solved it by using Zend_Db_Select object instead a query string:

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

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

Edited: Indented for code markup display.

I have the same problem. It seems that this is a Zend Bug.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM