I have the following method to get data in codeigniter.
// Obter Fase
public function obter_fase($id)
{
$this->db->from($this->tbl_empresa_fase);
$this->db->select("tbl_empresa_fase.*, IF(tbl_empresa_fase.crud = 'C', 'R', 'C') as crud", FALSE);
if (is_array($id))
{
$this->db->where_in('campanha_id',$id);
}
else
{
$this->db->where('campanha_id',$id);
}
$this->db->order_by('campanha_id');
$query = $this->db->get();
$item = $query->result_array();
return $item;
}
It works, but if the ID being searched does not exist in the database, an error is returned and with the above method, this is already expected.
For this reason, I want to know if there is a possibility of creating a condition that checks whether the searched ID exists in the database.
If yes, return result_array
, otherwise, return return []
.