How can I change this CodeIgniter query()
call into separate query builder methods?
$q = "SELECT u.token
FROM user u
WHERE u.userid = ?";
$r = $this->db->query($q, [$id]);
$this->db->close();
return count($r->result_object) == 1
? $r->row()->token
: 0;
$query = $this->db
->select('u.token')
->from('user u')
->where('u.userid', $id)
->get();
return ($query->num_rows() == 1) ? $query->row()->token : 0;