Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lock mysql table

Status
Not open for further replies.

yebaws

Technical User
Mar 22, 2007
42
GB
Could be one for sql forum rather than php, so please feel free to move it...

I am writing a php script that modifies a mysql database which more than one person may be accessing simultaneously and I need to lock the table for a short time to stop anyone else making modifications at the same time. I think I understand the syntax to lock and unlock the table, but my problem is this: If a user starts the modification process (an therefore causes the table to lock) but then doesn't complete it (so the table isn't unlocked) the table will remain locked. Is there a way to lock a table in such a way that the lock will expire after a given time?

Thanks!
 
Hi

yebaws said:
my problem is this: If a user starts the modification process (an therefore causes the table to lock) but then doesn't complete it (so the table isn't unlocked) the table will remain locked.
You mean 1) you intend to use the [tt]lock tables[/tt] statement and 2) you intend to use it form a PHP script run through a web server ?

Then you have no problem. The web server will terminate the script after [tt]max_execution_time[/tt] seconds and that will release the lock :
lock tables said:
If the connection for a client session terminates, whether normally or abnormally, the server implicitly releases all table locks held by the session (transactional and nontransactional).


Feherke.
[link feherke.github.com/][/url]
 
mysql manual said:
If the connection for a client session terminates, whether normally or abnormally, the server implicitly releases all table locks held by the session (transactional and nontransactional). If the client reconnects, the locks will no longer be in effect. In addition, if the client had an active transaction, the server rolls back the transaction upon disconnect, and if reconnect occurs, the new session begins with autocommit enabled.
 
great, problem solved!

Thanks for the replies!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top