You could use a transaction block if your database supports it, or just use 
some sort of auto-numbering field, such as SERIAL in Postgres, 
auto_increment in MySQL, etc. Then you wouldn't have to worry about 
retrieving the next cno before inserting a new row.


R wrote:

> Hi,
> In java servlets I used to use  a "synchronised" block of code to make 
> it was thread 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?
> Any help appreciated,
> -Ryan

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to