If you use the database mechanism to lock the table during the transaction, then the second simultaneous invocation of your PHP program will wait (a tiny fraction of a second) until the first one is done.
miguel On Wed, 29 May 2002, r wrote: > since only my one program was accessing the table the database was safe, > My question stands at what happens if 2 or more people access > "enterdetails.php", click on the submit button to enter info into the same > table at the same time? > since I will be returning a valid ID no for each of them.......Its basically > the old chopsticks puzzle and would like to know how does PHP handle it? > -Ryan. > > ----- Original Message ----- > From: "Miguel Cruz" <[EMAIL PROTECTED]> > To: "r" <[EMAIL PROTECTED]> > Sent: Tuesday, May 28, 2002 12:52 PM > Subject: Re: [PHP] Thread safe > > > > Well, that's not a thread safety issue if you're trying to lock a record > > in a database. If it was handled entirely within Java, then there was no > > guarantee of database referential integrity. Only the database can do > > that. > > > > miguel > > > > On Wed, 29 May 2002, r wrote: > > > Nope its not more like a database issue as this was clearly addressed in > > > java and so the "synchronised" keyword was made and you have to > implement a > > > "synchronised block" of code to make it thread safe..... > > > is this possible in PHP or does PHP itself take care to make all scripts > > > thread safe? > > > > > > Cheers, > > > -Ryan. > > > > > > ----- Original Message ----- > > > From: "Miguel Cruz" <[EMAIL PROTECTED]> > > > To: <[EMAIL PROTECTED]> > > > Sent: Tuesday, May 28, 2002 11:44 AM > > > Subject: Re: [PHP] Thread safe > > > > > > > > > > On Mon, 27 May 2002, r wrote: > > > > > In java servlets I used to use a "synchronised" block of code to > make > > > sure > > > > > it was thread safe...how do i do this in PHP? > > > > > > > > > > Heres what should be thread safe > > > > > > > > > > { > > > > > $r=select max(cno)+1 from MyTable; > > > > > (then i insert into the table the new cno plus my name) > > > > > insert into mytable ($r,'myname'); > > > > > } > > > > > How to do this and make sure its thread safe? > > > > > > > > More of a database issue. "select ... for update" is a good starting > point > > > > as you search the manual of your particular database platform. > > > > > > > > miguel > > > > > > > > > > > > -- > > > > PHP General Mailing List (http://www.php.net/) > > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php