Re: Back from the dead with a racing question!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jul 17, 2009, at 1:54 PM, Jason Pruim wrote:


On Jul 17, 2009, at 11:56 AM, Bastien Koert wrote:

On Fri, Jul 17, 2009 at 11:51 AM, tedd<tedd.sperling@xxxxxxxxx> wrote:
At 11:12 AM -0400 7/17/09, Jason Pruim wrote:

Hi everyone!

So some of you may have noticed that I have been away for quite awhile... Been trying to get settled (Moved across the country) and getting a job.

And now that that is done I have a question about a project that I might
be doing for my current employer and want to do it properly.

If all goes through, I'll be writing an online database that upwards of 10 people will be using at various times through out the day. Basically, in a form they fill out a model number, customer name, phone number etc. etc.. And then submit the form. After submitting they need to write the log number on some paperwork. If I have 2 people submit the form at the same time, I'm thinking I could end up with a race condition and they might get the wrong
log number (The log number is simply a consecutive record number)

Do I need to be reading up on locking tables/rows? Or in my situation as I've briefly described it do I not have to worry about it? Or is there a third door with the magic bullet that will solve all my problems? :)

Any advice is greatly appreciated as always, RTFMing is good as well, as
long as M is defined :)

I'm not afraid of google either, just need the right terms to hit it with so I don't go into "search overload" as the commercials for a rival search
engine claim :)

Thanks Everyone!

Jason:

Welcome back.

Clearly if you have two or more people checkout the same record at the same time and each edits the record then you ARE going to have problems when each
updates the record.

You can solve this problem by using transactions -- here's a link:

http://dev.mysql.com/doc/refman/5.0/en/lock-tables-and-transactions.html

When someone is editing a record, you also need to be able to show the next person(s) that the record they want is currently busy and not available. However, I'm not sure as to how to notify the next user that the table is locked via php. Perhaps a table status might provide that information. If
so, then use that to notify the next user.

As for your log of activity, just create a another record (with an
auto_increment index) in your activity log table and update that record with the data you need to record, such as user id, timestamp, what record they accessed and whatever else you want after the transaction is completed.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http:// earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



As a further note to tedd's reply on transactions, you will need to
use the INNODB engine in mysql should you want to use transactions.
Transactions here are done a row locking level not table so you should
have fewer issues.

I also just found out that unless I can convince them to host it off site, it'll be on a windows machine.... So php & mssql... Does that change alot?

To answer some of the other questions the Log number is currently just an auto incrementing consuctive number. So an auto+increment would work perfectly. What I'm trying to avoid is:

User1
User2

User1 submits to log number 12345
User2 submits to log number 12346

User1 is told their log number is 12346
User2 is told their log number is 12346

But User1 & User2 are on different computers... And if it's as easy as using the equivelant for: SELECT * FROM table WHERE UserID="User1" ORDER BY lognumber desc LIMIT 1; Then I'm good... I know how to proceed with writing it... Just need to figure out how to bill/sell it! ;)




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Here's something I do. One of our clients likes to see job numbers instead of record numbers. So, I simply convert the record number into a job number. It begins with the current year and then I pad it out to 10 characters. So, record number 72 becomes job number 2009000072.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux