Welcome Guest, Not a member yet? Register   Sign In
how can I create an empty database query object?
#5

[eluser]Colin Williams[/eluser]
You should employ the rule of a single exit point:

Code:
function getStuff($id=false)
{
    $result = array();
    if ($id)    
    {
        $result = $this->db->get_where( 'stuff', array('id' => $id) );
    }
    return $result;
}

Then you can come in later and put what you need in $result before the conditional. My hunch is that the reason your want an "empty" db object is because you want to avoid errors where your controller tries to use $result->row(), etc. Just don't be lazy and run an isset() check first. Actually, I wouldn't even return db objects ever.

You could also just run the query.. if id is FALSE, you'll get an empty result. (No sense in running a dummy query as previously suggested)

Code:
function getStuff($id=false)
{
    return $this->db->get_where( 'stuff', array('id' => $id) );;
}


Messages In This Thread
how can I create an empty database query object? - by El Forum - 04-08-2009, 10:42 AM
how can I create an empty database query object? - by El Forum - 04-08-2009, 10:47 AM
how can I create an empty database query object? - by El Forum - 04-08-2009, 10:54 AM
how can I create an empty database query object? - by El Forum - 04-08-2009, 02:25 PM
how can I create an empty database query object? - by El Forum - 04-08-2009, 10:27 PM
how can I create an empty database query object? - by El Forum - 04-09-2009, 04:29 AM
how can I create an empty database query object? - by El Forum - 04-09-2009, 05:02 AM
how can I create an empty database query object? - by El Forum - 04-09-2009, 05:08 AM
how can I create an empty database query object? - by El Forum - 04-09-2009, 06:01 AM
how can I create an empty database query object? - by El Forum - 04-09-2009, 07:06 AM
how can I create an empty database query object? - by El Forum - 04-09-2009, 01:03 PM
how can I create an empty database query object? - by El Forum - 08-20-2012, 07:53 AM
how can I create an empty database query object? - by El Forum - 08-20-2012, 07:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB