What features does PHP/MySQL provide to deal with concurrent systems?
E.g, If I have a table, and I only want to allow one user to update at any one time. I want to put a lock on the database until the update is complete, then once that request is processed, unlock the database and allow another user to update?

Recommended Answers

All 3 Replies

To my understanding, this is exactly how MyISAM and InnoDB both work with slight differences. MyISAM locks the entire table while InnoDB locks a row during an insert/update.

It appears you can manually lock and unlock a table for a query though if necessary.
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html

Some info on table locking in mysql
http://dev.mysql.com/doc/refman/5.0/en/table-locking.html
Some info on InnoDB locking
http://dev.mysql.com/doc/refman/5.0/en/innodb-lock-modes.html

You can add a timestamp and user columns to the table.
Use these to detect if the table is in use;
For example, if the initial test query returns null time and user, the update query is allowed.

Great! Thanks for your responses. I will have play around with what was suggested and get back to you. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.