3

I am calling multiple models in controllers and all models do database query. i did something like this

public function InsertSale()
    {
            $this->db->trans_start(TRUE);
            // all logic part and models calling which do insert/update/delete

            $this->db->trans_complete();
}

Above code is not working even if something fails after some queries they dont rollback.

tereško
  • 58,060
  • 25
  • 98
  • 150
Sainish Momin
  • 95
  • 1
  • 12

2 Answers2

1

Having true in $this->db->trans_start(true); will put the transaction in to test mode which means that, regardless of what happens, the query will be rolled back.

If you wanted to see if the query would work you would use:

$this->db->trans_status();

Which will return either true/false depending on the outcome.

Rwd
  • 34,180
  • 6
  • 64
  • 78
0

So that you have to follow like this

$this->db->trans_start(); # Starting Transaction
$this->db->trans_strict(FALSE); 

$this->db->insert('table_name', $someDataArray); # Inserting data

# Updating data
$this->db->where('id', $id);
$this->db->update('table_name', $someDataArray); 

$this->db->trans_complete();

This is work fine. Check this answer too

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85