Welcome Guest, Not a member yet? Register   Sign In
Database Transactions
#1

[eluser]Wuushu[/eluser]
Hi,

Sorry if this has been asked and answered before.


I've read through the documentation for database transactions.
And now my question; is it possible to start a transaction and then over (several) post steps (different pages/forms) have this transaction still valid, and upon completion of the final step of the form series, test the transaction and complete it should all of the queries be OK? The transactions are unique to the user?


Also, it is not often i use direct $this->db->query/method in my controllers, but rather with $this->model_name->insertSomething($data); Does transaction hook into any db queries ran in external models? Or just inline db-calls?

Thanks for swift replies!

Kind regards,
Christian
#2

[eluser]gtech[/eluser]
Quote:I’ve read through the documentation for database transactions.
And now my question; is it possible to start a transaction and then over (several) post steps (different pages/forms) have this transaction still valid, and upon completion of the final step of the form series, test the transaction and complete it should all of the queries be OK? The transactions are unique to the user?

humm to me it sounds a bit dangerous leaving a transaction open over two different pages, say you refreshed the page, that would mean the transaction would open again without being closed, rollback will not work and you may even lock the database. Thats if it is possible to use a transaction over multiple pages a different connection may be used (needs research), either way I don't think its a good idea.

surely it would be best to store the data from each step in memory (either by forwarding the post values or using a session variable) and then do the database modifications after the final step?

Quote:Also, it is not often i use direct $this->db->query/method in my controllers, but rather with $this->model_name->insertSomething($data); Does transaction hook into any db queries ran in external models? Or just inline db-calls?

I am not quite sure what you are asking here.. You can put the transaction in your controller method and then load two models (calling different methods) and then end the transaction in the same controller, as long as you do that within the same page request. I am sure that will work because the same db connection will be used.

I use transactions in the model... and then sometimes call another models method within the same transaction and rollback works, you do have to be careful you don't nest transactions (a transaction within a transaction) as rollback will not work.

I hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB