Welcome Guest, Not a member yet? Register   Sign In
Revising Function
#2

[eluser]apodner[/eluser]
You can just basically roll the first insert back if the 2nd one fails.
Code:
public function save_title($title_name, $title_directory_name, $title_status_id)
{
    $data = array(
     'title_name' => $title_name,
     'title_directory_name' => $title_directory_name,
     'title_status_id' => $title_status_id
    );

    $this->db->insert('titles', $data);  
    if ($this->db->affected_rows() == 1)
    {
        $insert_id = $this->db->insert_id();
        $data = array(
        'title_id' => $insert_id
        );

        $this->db->insert('title_champions', $data);

        if ($this->db->affected_rows() == 1)
        {
            return true;
        }
        else
        {
            $this->db->where('title_id', $insert_id);
            $this->db->delete('titles');
            return false;
        }
    }
    else {
        
        return false;
    }
}


Messages In This Thread
Revising Function - by El Forum - 12-01-2012, 06:24 PM
Revising Function - by El Forum - 12-13-2012, 09:05 PM
Revising Function - by El Forum - 12-14-2012, 10:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB