这是来自数据库的错误。
可以在/application/config/database.php
$db['default']['db_debug'] = FALSE;
否则隐藏,你可能要照顾它。我建议只是检查是否值已经存在:
$this->db->where('id', $id);
$query = $this->db->get('message_template');
$data = array(
'id' => $id,
'name' => $name,
'subject' => $subject,
'detail' => $detail,
'type' => $type,
'status' => $status,
'create_date' => $create_date
);
if($query->num_rows() > 0)
{
// the line already exists, so update
$this->db->where('id', $id);
$this->db->update('message_template', $data);
}
else
{
$this->db->insert('message_template', $data);
}
,或者,如果你要使用原始查询的意愿,这应该是稍快(我不会真的担心通过ID搜索)
$sql = "INSERT INTO message_template
(id, name, subject, detail, type, status, create_date)
VALUES (1, " + $this->db->escape($name) + ", " + $this->db->escape($subject) + ", " + $this->db->escape($detail) + ", " + $this->db->escape($type) + ", " + $this->db->escape($status) + ", " + $this->db->escape($create_date) + ")
ON DUPLICATE KEY UPDATE name=" + $this->db->escape($name) + ", subject=" + $this->db->escape($subject) + ", detail=" + $this->db->escape($details) + ", type=" + $this->db->escape($type) + ", status=" + $this->db->escape($status) + ", create_date=" + $this->db->escape($create_date) + ";";
否则,请查看DataMapper ORM,因此您的所有数据库内容都会自动处理。