$data = [
'the data you want to save' => '',
];
$query = $this->db->get_where('tableName', ['id' => $id]);
if ($query)
{
$this->db->update('tableName', $data);
return true;
}
else
{
$this->db->insert('tableName', $data);
return $this->db->insert_id();
}