07-13-2017, 07:42 PM
>There are plenty of times I think there will ALWAYS be results and then I break something
I recommend to write:
or to have an empty result array in case of error so that foreach will not happen:
>Assigning the query to a variable lets me get both a count and results or first
You can just do this:
I recommend to write:
Code:
if (!$db->error() && $db->count()>0)
or to have an empty result array in case of error so that foreach will not happen:
Code:
$array = !$db->error() ? $db->results(true) : [];
Code:
foreach ($array as $item) {};
>Assigning the query to a variable lets me get both a count and results or first
You can just do this:
Code:
$first = $db->query($sql)->first();
Code:
$count = $db->count();