0

Is there a way to lock table entries in SQL/MySQL? I'm looking for something like this (in php, but it should not matter):

Pseudo-Code:

waitForTableEntryWithKey("somekey");
lockTableEntryWithKey("somekey");

doSomethingWithSQL();

unlockTableEntryWithKey("somekey");

doSomethingWithSQL() must not be executed more than one time at a time for a certain table entry. Is there a way to do this in SQL, except for creating a locked bool in the table and querying it while waiting (it just seems like an improper solution)?

l'arbre
  • 719
  • 2
  • 10
  • 29
  • Is this what you are looking for? https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html and https://stackoverflow.com/questions/3662766/sql-server-how-to-lock-a-table-until-a-stored-procedure-finishes – Krzysztof Boduch Jul 13 '17 at 13:49
  • I don't want to lock the whole table. Just one row. – l'arbre Jul 13 '17 at 16:14

1 Answers1

0

I think you are speaking about row lock ant it can be achieved with MySQL InnoDB. Please take a look into MySQL documentation. How it should be described in the PHP script is very depends on the tools which you are using for communication with DB.

Neodan
  • 5,154
  • 2
  • 27
  • 38