On Fri, Jul 17, 2009 at 11:54 AM, Jason Pruim<ja...@jasonpruim.com> wrote:
> On Jul 17, 2009, at 11:56 AM, Bastien Koert wrote:
>> On Fri, Jul 17, 2009 at 11:51 AM, tedd<tedd.sperl...@gmail.com> 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
>>>> 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
>>>> people will be using at various times through out the day. Basically, in
>>>> form they fill out a model number, customer name, phone number etc.
>>>> And then submit the form. After submitting they need to write the log
>>>> on some paperwork. If I have 2 people submit the form at the same time,
>>>> thinking I could end up with a race condition and they might get the
>>>> 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
>>>> so I don't go into "search overload" as the commercials for a rival
>>>> engine claim :)
>>>> Thanks Everyone!
>>> Welcome back.
>>> Clearly if you have two or more people checkout the same record at the
>>> time and each edits the record then you ARE going to have problems when
>>> updates the record.
>>> You can solve this problem by using transactions -- here's a link:
>>> When someone is editing a record, you also need to be able to show the
>>> 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
>>> 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.
>>> 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 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! ;)
Each time a user visits a php script it is executed in a separate
process. Even though they are likely running as the same database
user, each instance of the script is creating separate connections to
the database which are insulated from each other. Each connection
uses separate transactions (though they are autocommit so you might
not realize it) so auto_increment will take care of proper numbering.
Then simply use mysql_insert_id() after your INSERT to get the last
auto_increment value generated in that instance of the script, don't
even worry about the query. However, if you do need the full record
to throw back at the user then build the query string like this:
$sqlQuery = 'SELECT * FROM table WHERE logID=' . mysql_insert_id();
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php