473,569 Members | 2,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Concurrent Updates - Solutions

blyxx86
256 Contributor
Good Morning Everyone,

I am making a PHP web frontend for a MySQL database. I have finally started to create the UPDATE portions of the website and am wanting some opinions/feedback as to what I'm trying to do.

Since it is a webpage and not a direct, always connected, link to the database the DBMS will assume an optimistic locking method. I am using InnoDB.

What I am thinking of doing to ensure that concurrent SQL UPDATE statements don't mess with the same record I was going to create hidden form variables of the "old" values and then when the form is submitted compare those "old" values to the ones currently in the database when the submit button is clicked. If they are the same (all of them), then I will allow the UPDATE command to take place. If not, an error message would be thrown.

Is there a better way to handle the situation with concurrent (or someone updating a record in one tab, and thinking they didn't update it in another) updates?

Thanks again!
Kyle

PS. I'm pretty sure this belongs in the MySQL section and not PHP, but please let me know if I'm wrong.
Jan 5 '09 #1
6 5827
debasisdas
8,127 Recognized Expert Expert
why not lock the database table once in edit mode .
Jan 6 '09 #2
blyxx86
256 Contributor
I thought about doing that as well, but what happens if they close the window while they are updating it? I know InnoDB supports row-level locking and that is ideal, but I was worried that if the user cancels out without pressing a "cancel" button then the row will remain locked until the dbms decides it shouldn't be anymore.

Is there an ideal way of locking that you would suggest that works well for web-based apps like the one I'm developing?
Jan 6 '09 #3
r035198x
13,262 MVP
@blyxx86
What if the database values are changed just after you checked that they are OK and then someone else updates them just before you set the new values?
Jan 7 '09 #4
blyxx86
256 Contributor
Perhaps instead of doing the initial preliminary SELECT, I can do the UPDATE with a lengthy WHERE statement.

Would that be ideal?
Jan 7 '09 #5
r035198x
13,262 MVP
No use. Your where clause would presumably contain a select after which an update can be done from elsewhere. Better synchronize the parts of the code that change the database in a possibly inconsistent manner.
Also have a look at internal-locking.
Jan 8 '09 #6
blyxx86
256 Contributor
So running:
Expand|Select|Wrap|Line Numbers
  1. UPDATE table(columna, columnb)
  2. VALUES ('A', 'B')
  3. WHERE (columna=oldvaluea)
  4.    AND (columnb=oldvalueb)
  5.    AND (id=updateid)
  6.  
So instead of updating based only off of the id column, it would match the entire contents before finding whether or not it can update the row.

I don't think it would be wise to lock a row/table when someone chooses to "Edit" a record with a PHP based webpage.

I suppose locking the table/row when the "Submit" button is pressed and still performing the extended WHERE statement in the UPDATE sql would still be necessary.

How else would be ideal to cope with this type of situation?
Jan 8 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1470
by: Mike Meyer | last post by:
The recent thread on threads caused me to reread the formal definition of SCOOP, and I noticed something I hadn't really impressed me the first time around: it's using staticly checkable rules to help ensure correct behavior in a concurrent environment. That's impressive. That's *really* impressive. I know of no other language that does...
11
5422
by: Durai | last post by:
Hi All, I tested "concurrent testing" in MySQL. It works fine. But I couldn't do in PostgreSQL 7.3.4 on HPUX IPF. I got deadlock problem. I used the PHP script to update table( one script increment the column & another one decrement the column). Is the postgres support the concurrent access to update database? I got the following errors: ...
1
1201
by: Babz | last post by:
Hi, How I can prevent concurrent updation of a records in .net. I am using Dataset which is disconnected from the data source. In this situation if two users opens the same record, modifies the data and updates one after another, my data won't be in the correct state. How I can prevent this. Is there any locking technics.
6
2906
by: John Smith | last post by:
I have a C++ program which appends new text to a file. Multiple instances of this program may run concurrently, hence there is a possiblity that 2 or more instances (say C1 and C2) of this C++ program will be modifying the file at the same time. I want to make sure that C1 can finish appending it's changes to the file, before C2 starts to...
1
1691
by: Jay Douglas | last post by:
Sorry for the cross post but I was hoping between developers and systems ppl I can get answer to this question. I've searched; found issues similar to mine but the solutions are not working. My situation: I have an ASP.net web app running on Server 2003 (Server 1) that calls a service on a different Server 2003 (Server 2) via HTTP. ...
3
5971
by: Subrat Das | last post by:
Hi, I have a java application which calls a stored procedure to insert data into a table.Multiple threads of java call the same procedure at the same time. Sometimes it happens that few threads send the same data as parameter to the procedure. In that case i get the error : "Cannot insert duplicate key row in object ...." The functionality of...
8
1932
by: Dica | last post by:
i've got an app that needs to install a named instance of SQL Express. VS 2005 allows me to specify required components for my setup project, but named instances of SQL Express isn't supported. so, my main setup MSI needs to execute the SQL Express MSI (a concurrent installation). technically, this is possible, but this is frowned upon by MS...
10
4488
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under consideration here is that it is supplied to the AsyncOperationManager.CreateOperation(userSuppliedState) method... with userSuppliedState being, more...
0
1126
by: raaman rai | last post by:
This is quite irratiting to find out that my system is enabled with automatic updates and it periodically updates my pc with the latest updates. But recently i encountered network problem once the updates get installed. Then i had to restore my system and it worked but again the updates were left to run as usual. And again i got the same problem...
0
7698
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.