Jump to content

what if browser hang or suddently terminate?


zgkhoo

Recommended Posts

mysql_query('BEGIN TRANSACTION_NAME');

mysql_query('SELECT * FROM whatever...')
mysql_query('UPDATE blah blah...')

if(check for errors) {
mysql_query('ROLLBACK');
} else {
mysql_query('COMMIT');
}

 

 

wat if the  browser hang or suddently terminate? then it wont have chance to run  if(check for errors) and perform the rollback or commit.... will lead to database confilict  :-\ :-\

 

 

  • 2 weeks later...

If you terminate the mysql connection without committing, the transaction will be rolled back.

 

Think about it from mysql's view .. it doesn't know if your transaction is complete until you say "commit".  So if you stop without saying "commit", it is better for it to abandon all changes than to possibly commit partial changes.

 

If the changes conflict with each other, then usually one script will get an error, the other will complete normally.  If the changes do not conflict, both scripts will succeed.

 

If you commit for one user, it will not commit another user's transaction.

If you terminate the mysql connection without committing, the transaction will be rolled back.

 

Think about it from mysql's view .. it doesn't know if your transaction is complete until you say "commit".  So if you stop without saying "commit", it is better for it to abandon all changes than to possibly commit partial changes.

 

If the changes conflict with each other, then usually one script will get an error, the other will complete normally.  If the changes do not conflict, both scripts will succeed.

 

If you commit for one user, it will not commit another user's transaction.

 

how mysql differential user? using BEGIN and COMMIT?

BEGIN meant start a new connection?

 

 

mysql_query('BEGIN TRANSACTION_NAME'); 

do i need to put in TRANSACTION_NAME? wat if i didnt put transaction name?

Mysql identifies user by connection.  A new script will use a new connection, therefore a new transaction.  You do not need a transaction name.

 

If 2 users call your script and each starts a transaction, mysql knows the difference.  It will not mix them up.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.