Welcome Guest, Not a member yet? Register   Sign In
Cancelling current transaction started with $this->db->trans_start()
#1

[eluser]teomor[/eluser]
I'm using $this->db->trans_start() to start a transaction and $this->db->trans_complete() to commit the changes, but what if I want to cancel the whole thing in the middle of it? Can I just use $this->db->trans_rollback()? Would that work on the whole transaction group?
The documentation only says to use $this->db->trans_rollback() when manually starting transactions with $this->db->trans_begin(). I'm a bit confused if this would work or not..
#2

[eluser]letsgolee[/eluser]
if I'm right, you can rollback all, I think though I have not tested yet.

Transactions are started when $this->db->trans_start() is calling, and it can be called as many as you want.
if something is wrong and you want rollback all then we must know what depth of transaction and the depth is recorded using $this->db->_trans_depth. So the rollback function must be called as many as the nested transactions.

Code:
$this->db->trans_start();
...
$this->db->trans_start();
...

if (/* something is wrong and you want roll back all */) {
while ($this->db->_trans_depth) {
  $this->db->trans_rollback();
  $this->db->_trans_depth--;
}
}
#3

[eluser]teomor[/eluser]
Right. So as long as I call trans_rollback as many times as I call trans_start I should be OK, that's what your're saying, correct? Smile
As it happens, that's exactly what I am doing..




Theme © iAndrew 2016 - Forum software by © MyBB