zgkhoo Posted December 12, 2007 Share Posted December 12, 2007 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 :-\ :-\ Quote Link to comment Share on other sites More sharing options...
fenway Posted December 12, 2007 Share Posted December 12, 2007 This is a backend script... it has nothing to do with the browser. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted December 21, 2007 Author Share Posted December 21, 2007 will this script rollback or commit others user transaction??? eg..this page i commit....but there is another user at another page that making transaction but havent commit yet.....will i commit others user transaction too? Quote Link to comment Share on other sites More sharing options...
btherl Posted December 21, 2007 Share Posted December 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
zgkhoo Posted December 21, 2007 Author Share Posted December 21, 2007 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? Quote Link to comment Share on other sites More sharing options...
btherl Posted December 23, 2007 Share Posted December 23, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.