|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Lock tables
Hi all,
I have a script where I made a SELECT and a button to edit each row. This button will open another php script which has 3 options: UPDATE, DELETE or cancel. The problem is: when a user1 opens a record and if a user2 tries to open the same record, I want that the user2 couldn't open or UPDATE that record. How can I solve this ? With PHP or SQL ? I know the lock only exists for the life of the thread (or until the script ends which is my case, because I have several scripts) Please help, Andre |
|
#2
|
|||
|
|||
|
RE: Lock tables
You should solve it with PHP.
Generaly you can manage locks in most databases. You can lock table with command, however it is not recommanded approach. |
|
#3
|
|||
|
|||
|
RE: Lock tables
How can I do that ? I have an idea: create a field status (1 - lock record or entire table, 0 - unlock) in my table. And I will need to have a script that never expires (like a thread). The script should make a verification of this field with a if. This is possible ?
|
|
#4
|
|||
|
|||
|
RE: Lock tables
Well, I am not good enough in PHP to tell you this. Probably someone more expirienced will come.
However one solution could be to add boolean column to your db structure and use it to indicate if row is currently locked or not. However in high trafic environment this can cause big concurency problems. So "not in database layer" solution could be better choice. We will see if someone will come and tell us. |
|
#5
|
|||
|
|||
|
RE: Lock tables
In this case I don't have high trafic environment. How can I make a script that never expires. My scripts only had a few seconds of life (only make a SELECT or an UPDATE).
|
|
#6
|
|||
|
|||
|
RE: Lock tables
So if you have not high trafic environment. Just add something like "Locked" collumn to your table and set it to 0 (= not locked). Each time someone will start to work with certain row, set "Locked" collumn in this row with update to 1 (locked).
Each time someone will try to start to work with certain row, check if it has 0 value in "Locked" collumn. |
|
#7
|
|||
|
|||
|
RE: Lock tables
I already solved this problem. Now I've got a doubt with Javascript. When I opens the php script to edit, I change my field status to 1 to lock the registry and I've got 3 buttons: UPDATE, DELETE or cancel. If I press one of this buttons I change my field status to 0 to unlock the registry. Now if I press the close button in the right corner of the browse, the status field doesn't change and I need to change it to 0. How can I do this ?
|
|
#8
|
|||
|
|||
|
RE: Lock tables
|
|
#9
|
|||
|
|||
|
RE: Lock tables
Well, I already lock the table. My doubt is about Javascrip, I don't if here is the best place to put this question. How can I know if anyone press in the close button of the browser ?
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Lock tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|