[英]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: 我有一个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;
}
}
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
致命错误:未捕获的异常'Zend_Db_Statement_Exception',消息'SQLSTATE [21000]:基数违规:1241操作数应包含1列(s)'
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.
我正在为一个列发送2个值。 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: 我像你一样工作,但最后我通过使用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);
Edited: Indented for code markup display. 编辑:缩进代码标记显示。
I have the same problem. 我也有同样的问题。 It seems that this is a Zend Bug.
看来这是一个Zend Bug。
Source: http://framework.zend.com/issues/browse/ZF-3311 资料来源: http : //framework.zend.com/issues/browse/ZF-3311
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.