我正在尝试使用以下代码更新数据,但它生成了错误的SQL查询。不明白为什么会产生错误的错误。请帮帮我。
$data = array();
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
$this->Pers->id = $results['Pers']['persID'];
$this->Pers->save($data);
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bdr+.pers.persID' in
'where clause'
SQL Query: UPDATE `bdr+`.`pers` SET `etat` = 1, `Activation` = '',
`date_time` = '2014-03-19 11:33:21' WHERE `bdr+.pers.persID` = 37
这意味着bdr+.pers.persID
生成错误。不要理解它为什么会这样产生。
答案 0 :(得分:0)
您的代码包含bdr+.pers.persID` = '37'
,因为$results['Pers']['persID']
提供37
答案 1 :(得分:0)
检查此$results['Pers']['persID']
变量是否返回正确的格式
然后尝试这个
$data = array();
$data['Pers']['persID'] = $results['Pers']['persID'];
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
//Just to make sure your model is loaded
$this->loadModel('Pers');
if ($this->Pers->save($data, false)) {
echo 'Pres has been saved :) ';
}