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 :-\ :-\ Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/ 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. Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/#findComment-412967 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? Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/#findComment-420264 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. Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/#findComment-420304 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? Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/#findComment-420311 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. Link to comment https://forums.phpfreaks.com/topic/81340-what-if-browser-hang-or-suddently-terminate/#findComment-421406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.