Welcome Guest, Not a member yet? Register   Sign In
Has DELETE been successful?
#1

[eluser]brainer[/eluser]
Just wondering if there is anyway of checking if a DELETE with the active record class has happened? It's possible that sometimes a DELETE will be attempted when that id doesn't exist.

This is my code:

Code:
function delete($id)
    {        
        $this->db->where('id', $id);
        $this->db->delete('table');
    }
#2

[eluser]brainer[/eluser]
$this->db->affected_rows()
#3

[eluser]joedy[/eluser]
function delete($id)
{
$this->db->where('id', $id);
$result = $this->db->delete('table');
return $res;
}
#4

[eluser]Phil Sturgeon[/eluser]
Using $this->db->affected_rows() will give you a 0 (could be confused with FALSE) when a query runs but matches no rows.

Getting a true boolean response is as simple as:

Code:
return (bool) $this->db->delete();

Errors return false but if the query executes it will give you a TRUE even if no rows were affected.




Theme © iAndrew 2016 - Forum software by © MyBB