Welcome Guest, Not a member yet? Register   Sign In
Transaction question
#1

[eluser]jepotski[/eluser]
I have this functions:
Code:
function add2(){
//contains insert statements
}

function add1(){
   $this->db->trans_begin();

  

   //contains insert statements.
   $this->add2();

   if ($this->db->trans_status() === FALSE){
    $this->db->trans_rollback();
   }else{
    $this->db->trans_commit();
   }
}


My question is if the insert query in function add2 fails, will it rollback the insert statements in function add1?
#2

[eluser]sketchynix[/eluser]
yes
#3

[eluser]jepotski[/eluser]
[quote author="sketchynix" date="1286924383"]yes[/quote]

thanks. so all of the queries inside the trans begin, regardless if its from a function, will be rolled back or commited?
#4

[eluser]sketchynix[/eluser]
yes, you are sending commands to the database through PHP. The database has no idea what php function it comes from, so it will just see
transaction start
insert
insert
rollback or commit.
#5

[eluser]jepotski[/eluser]
[quote author="sketchynix" date="1287013268"]yes, you are sending commands to the database through PHP. The database has no idea what php function it comes from, so it will just see
transaction start
insert
insert
rollback or commit.[/quote]

Thanks. Now Its clarified.

BTW. Does CI and MySQL support nested transactions?
#6

[eluser]sketchynix[/eluser]
Quote: Does CI and MySQL support nested transactions?
Not that I am aware of, though I haven't checked the mysql docs recently. I'm using version 5.1
#7

[eluser]jepotski[/eluser]
[quote author="sketchynix" date="1287042983"]
Quote: Does CI and MySQL support nested transactions?
Not that I am aware of, though I haven't checked the mysql docs recently. I'm using version 5.1[/quote]

Okay. I will check the manual.

One more question, what if I started a transaction and a PHP error occurred making my transaction open, will it automatically rollback or close my transaction on a specific time interval? Like in Java's JOTM, a transaction timeout can be set.
#8

[eluser]sketchynix[/eluser]
Look at innodb_lock_wait_timeout. I have no experience with Java, so I am not going to say it's the same thing, but i think that it is similar... if not, I have no clue Smile
#9

[eluser]jepotski[/eluser]
[quote author="sketchynix" date="1287044846"]Look at innodb_lock_wait_timeout. I have no experience with Java, so I am not going to say it's the same thing, but i think that it is similar... if not, I have no clue Smile[/quote]

Okay. Thank you for the answers. :lol:
#10

[eluser]jepotski[/eluser]
BTW. Do you know some articles regarding MySQL transactions? I want to read a topic about when not to use a transaction, and other best practices regarding transactions.




Theme © iAndrew 2016 - Forum software by © MyBB