Welcome Guest, Not a member yet? Register   Sign In
Proper way to return sql results
#1

[eluser]GeXus[/eluser]
Hey guys, I've been handling my queries like this:

Code:
function getSomething(){
  
  $query = $this->db->query("QUERY");
  return ($query->result_array()) ? $query->result_array() : false;

}

By doing it this way (checking if its true first, then returning it) cause the query to be run twice? Would it be better to store the query in a variable, then do the check on that variable?
#2

[eluser]WanWizard[/eluser]
The query runs only once, that's not a problem.

It does uses some memory and processing as you fetch the resultset twice. You can do
Code:
if ( $query->num_rows() )
{
    return $query->result_array()
}
else
{
    return FALSE;
}




Theme © iAndrew 2016 - Forum software by © MyBB