Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 26th, 2003, 09:07 AM
atflm atflm is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 atflm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old November 26th, 2003, 10:54 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
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.

Reply With Quote
  #3  
Old November 26th, 2003, 11:10 AM
atflm atflm is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 atflm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 ?

Reply With Quote
  #4  
Old November 26th, 2003, 11:20 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
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.

Reply With Quote
  #5  
Old November 26th, 2003, 11:30 AM
atflm atflm is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 atflm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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).

Reply With Quote
  #6  
Old November 26th, 2003, 11:36 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
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.

Reply With Quote
  #7  
Old November 26th, 2003, 04:40 PM
atflm atflm is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 atflm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 ?

Reply With Quote
  #8  
Old November 26th, 2003, 04:44 PM
zackcoburn zackcoburn is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 184 zackcoburn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Lock tables


Reply With Quote
  #9  
Old November 26th, 2003, 04:55 PM
atflm atflm is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 10 atflm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 ?

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Lock tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT