Welcome Guest, Not a member yet? Register   Sign In
Tip: toggling a boolean database column
#2

[eluser]TheFuzzy0ne[/eluser]
Nice idea, I like it. Thanks for posting. I'd just like to add, that for anyone using the Active Record library, you'll need to be careful, as the query probably won't be escaped correctly. This is what I had to do in my model to stop it from happening.

Code:
function _update($forum)
    {
        $this->db->where('id', $forum['id']);
        
        foreach ($forum as $key => $val)
        {
            $escape = TRUE;
            if (preg_match('/^([a-z0-9_]+)\s?\+\s?\d+$/i', $val, $matches))
            {
                if (isset($this->fields[$matches[1]]))
                {
                    $escape = FALSE;
                }
            }
            
            $this->db->set($key, $val, $escape);            
        }
        
        unset($forum);
        
        return $this->db->update($this->table);
    }

I had to loop through the data array, and set each field separately, after checking whether or not it needed escaping. It may need modifying to work with the code above, however.


Messages In This Thread
Tip: toggling a boolean database column - by El Forum - 06-29-2009, 10:24 AM
Tip: toggling a boolean database column - by El Forum - 06-29-2009, 10:46 AM
Tip: toggling a boolean database column - by El Forum - 07-03-2009, 12:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB