I wrote 2 possibilities to return the number of results using CodeIgniter, as follows:
public function get_num_indicados($id_usuario)
{
$query = $this->db->query("SELECT count(id_patrocinador) as num FROM usuarios WHERE id_patrocinador = ?", array($id_usuario));
$row = $query->row();
return $row->num;
}
public function get_num_indicados($id_usuario)
{
$query = $this->db->query("SELECT * FROM usuarios WHERE id_patrocinador = ?", array($id_usuario));
return $query->num_rows();
}
Doubt: What is the correct way and why? Is it indifferent? What about performance for MySQL?