473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Concurrent Updates - Solutions

blyxx86
256 100+
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 5816
debasisdas
8,127 Expert 4TB
why not lock the database table once in edit mode .
Jan 6 '09 #2
blyxx86
256 100+
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 8TB
@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 100+
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 8TB
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 100+
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
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...
11
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...
1
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...
6
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++...
1
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...
3
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...
8
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,...
10
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.