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  :-\ :-\

 

 

Link to comment
Share on other sites

  • 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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.