我有PHP:
if($post['for']){
foreach($post['for'] as $value){
$saveMsgObjFor->message_id = $save;
$saveMsgObjFor->object_type_id = 4;
$saveMsgObjFor->object_ref_id = $value;
$saveMsgObjFor->object_email = null;
$saveMsgObjFor->save($update);
}
}
但它只是保存了第一个循环。两次,它显示错误:
Statement could not be executed (23000 - 1062 - Duplicate entry
'33' for key 'PRIMARY'
33
是字段message_object_id
,它是auto increment
。请帮帮我..
答案 0 :(得分:2)
根据hint in this answer,您似乎需要明确将message_object_id
设置为null
。第一轮它默认为null
,但是在save()
之后它被设置为auto increment
值,因此您需要明确地重置它,例如:
foreach($post['for'] as $value){
$saveMsgObjFor->message_object_id = null;
$saveMsgObjFor->message_id = $save;
答案 1 :(得分:0)
我认为您应该从代码中删除以下行:
$saveMsgObjFor->message_id = $save;
我对Zend框架并不过分熟悉,但看起来你正在尝试为auto_increment分配相同的值,这不会起作用,因为它是行的标识符,必须是唯一的。希望这有帮助!