2

I read a lot about locking databases, tables and rows but i want lower lock, like lock only 'operation' i don't know how to call it, lets say i have function in php:

function update_table()
{
    //querys like SELECT, UPDATE INSERT etc.
}

Now, i want to only one person can use this function at the same time, and other will need to wait until the first one finish

But it is possible to lock not table/row but only this function, so others queries with SELECT etc. can be executed with no problem? or maybe better is just lock the table? (problem is that this table is very important and i don't want to lock it because some other users can visit the site for other resons/other pages and if many people will wait in line for this code above, other visitors also will have to wait even that they have no interests in site with code above)

1 Answer 1

2

Yes. You can use GET_LOCK and RELEASE_LOCK mysql functions

Sign up to request clarification or add additional context in comments.

2 Comments

But to be clear, GET_LOCK blocks only other GET_LOCK queries with the same name right?
Sure. But you want to lock whatever happens in your function, not to block any specific query, right :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.