I have a sql problem and I don't know how to fix it, I tried a few things, but ... you know. Here is my request:
/** * 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 mistake is:
Fatal error: throw exception "Zend_Db_Statement_Exception" with the message "SQLSTATE [21000]: cardinality violation: 1241 The operand must contain 1 column" in
Any help?
I had the same problem, in the end I found that I was sending the wrong value for the column. I sent 2 values for a column. So, check the value of your parameters provided by your function.
? :
/** * 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; } }
, , , , , 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);
: .
. , Zend.
: http://framework.zend.com/issues/browse/ZF-3311