Welcome Guest, Not a member yet? Register   Sign In
Need help with CI Query Error Handling
#2

[eluser]Cristian Gilè[/eluser]
Hi dazzlers,

close the transaction at the end of the foreach loop:

Code:
function dbInsertInformationToDB($data_array)
    {
        $returnID = "";
        $uniqueDataArray = array();
        
          // I prepare a array of values here
        $uniqueTableList = filter_unique_tables($data_array[2]);
        $this->db->trans_begin();

        // inserting is done here
// when there is a query error in $this->db->insert().. it is not rolling back the previous query executed

        foreach($uniqueTableList as $table_name)
        {
            $uniqueDataArray = filterDataArray($data_array,$table_name,2);
            $this->db->insert($table_name,$uniqueDataArray);
            if ($this->db->_error_message())
            {
                $error = "I am caught!!";
            }
            $returnID = $this->db->affected_rows();
        }
        
        $this->db->trans_complete(); // transaction completed
        
        if ($this->db->trans_status() === FALSE)
        {
            $this->db->trans_rollback();
        }
        else
        {
            $this->db->trans_commit();
        }
        
        return "ERROR";
    }


Cristian Gilè


Messages In This Thread
Need help with CI Query Error Handling - by El Forum - 01-12-2011, 08:48 PM
Need help with CI Query Error Handling - by El Forum - 01-13-2011, 03:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB