0

I'm developing a website, so when a user hits a button the following sample sql code is run. This is for registeration and basically meant to take information entered in a form and save it.

BEGIN TRAN
*sql code*
*sql code*
COMMITT TRAN 

BEGIN TRAN
*sql code*
COMMITT TRAN 

IF *sql code*
BEGIN 
ROLLBACK TRAN
END

in the above code there are several transactions - information being inserted into several tables, if not all goes as planned we rollback the transactions. But if someone presses the button for this script to execute then suddenly hits the 'x' or stop execution button on their browser; leading the execution of the code to stop and never reach the point where the transaction can be rolled back what can we do then?

This will mean the database can often end up with tables that have half filled columns or some linked tables where table X that is linked to table Y doesn't contain any information. Can this kind of thing even happen? Sorry I'm not too well versed in sql 'transactions' at the moment so any help would be nice.

Edited by asif49

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by LastMitch
0

Why don't you just delete lines 4, 6 and 8 then add an ELSE COMMIT TRANSACTION after line 13? That puts everything in the same transaction.

Edited by Ancient Dragon

0

@asif49

in the above code there are several transactions - information being inserted into several tables, if not all goes as planned we rollback the transactions. But if someone presses the button for this script to execute then suddenly hits the 'x' or stop execution button on their browser; leading the execution of the code to stop and never reach the point where the transaction can be rolled back what can we do then?

This will mean the database can often end up with tables that have half filled columns or some linked tables where table X that is linked to table Y doesn't contain any information. Can this kind of thing even happen? Sorry I'm not too well versed in sql 'transactions' at the moment so any help would be nice.

Can you actually show some of the code with the query?

If you don't understand how the query works and you also don't have a code for it then here are couple of sites that provide some MySQL Transactions code

Read this:

http://www.phpknowhow.com/mysql/transactions/

or this:

http://tympanus.net/codrops/2009/09/01/using-mysql-transactions-with-php/

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.