Lynn Thames
asked on
In Codeigniter, how can I check for results from SQL query to database?
In my database model, I have a function that accepts an SQL statement as a parameter and returns the results in what I believe is an array of objects.
But if no records are found, it is returning "0" instead of an array of objects.
I know this can't be right because I get syntax errors when I try to test the returning results when no records are found.
What would be the proper way to handle this so that the controller can check to see if any results are returned before calling the view?
Code is attached.
But if no records are found, it is returning "0" instead of an array of objects.
I know this can't be right because I get syntax errors when I try to test the returning results when no records are found.
What would be the proper way to handle this so that the controller can check to see if any results are returned before calling the view?
Code is attached.
function Fetch_query($sql)
{
$results = $this->masters->query($sql);
if($results->num_rows()>0):
$results = $results->result_array();
return $results;
else:
return "0";
endif;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you!