Prova detta
public function save($data, $id)
{
$query = $this->db->query("SELECT * FROM table_name WHERE id = '{$data['id']}' ");
$result = $query->result_array();
$count = count($result);
if (empty($count)) {
$this->db->insert('mytable', $data);
}
elseif ($count == 1) {
$this->db->where('id', $data['id']);
$this->db->update('mytable', $data);
}
}