faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

46 of 53 people (87%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I lock and unlock tables using PHP and MySQL?

Jan 24th, 2001 22:59
Joshua Ariizumi, Gary Smith,


This code will lock table1 so it can be updated without the WHERE 
condition possibly being altered:
mysql_query("LOCK TABLES table1 WRITE;") or die("Can't lock tables");
mysql_query("UPDATE table1 SET ...... WHERE ....") or die("Can't 
perform update");
mysql_query("UNLOCK TABLES");
As long as both locking and unlocking are done in the same script, 
locking should go fine.