random1 Posted February 21, 2008 Share Posted February 21, 2008 Hi All, How do you do transactions and lock tables in mySQL? I am running an application that requires the use of transactions. I also want to enforce locking rules so that users of my website don't edit the same data and the same time. How do I do this? ??? Link to comment https://forums.phpfreaks.com/topic/92358-mysql-php-transactions-and-table-locking/ Share on other sites More sharing options...
aschk Posted February 22, 2008 Share Posted February 22, 2008 <?php // Start transaction mysql_query("BEGIN"); // do lots of SQL'y stuff here... // Commit transaction. mysql_query("COMMIT"); ?> Locking tables is not a good idea, and in fact MySQL deals with it's own version of row/table locking so that you don't have to bother with it. Because you're using a transaction until the item is commited they're working with a virtual copy of the table, i.e. what they see while inside the transaction doesn't actually represent what is in the current table layout. Thus, you don't need to worry about it. MySQL will deal with all the thinking for you. Link to comment https://forums.phpfreaks.com/topic/92358-mysql-php-transactions-and-table-locking/#findComment-473680 Share on other sites More sharing options...
able Posted February 22, 2008 Share Posted February 22, 2008 Hopefully it goes without saying, but you need to make your tables either innodb or bdb for transactions to work. If you don't, you can still perform begin/commit/rollback - but they won't have any effect. Link to comment https://forums.phpfreaks.com/topic/92358-mysql-php-transactions-and-table-locking/#findComment-474090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.