$result=mysql_query("INSERT INTO threads (title,parentboardID) VALUES ('$title','$boardID')");
$threadID= //What goes here to find threadID of last entry?
$result=mysql_query("INSERT INTO posts (message,parentthreadID) VALUES ('$message','$threadID')");
It's no good using the most recent entry, since if two users post at once, that may not be the correct entry by the time the script runs.
Last edited by RFairey on Sat Jul 19, 2003 10:28 am, edited 1 time in total.
Does that return the ID of the last insert from this script, or from all scripts running? If two users post, then this function will return only the most recent ID, so the one posted first gets lost.
It returns most recent for current thread yeah, you should capture it immediately after query and only once. If you have multiple db connection and queries in progress within the same thread (script) you should always use link and resource identifiers for every db function (as the manual indicates).
most RDBMS have a sequencer type system yeah, but not many use Autoincrement columns the same way as mysql does..
Others are typically a INT column NOT NULL and default value is thefunctionthatgetsasequencenumber('sequencename') or something like that
I see... so theres nothing in either raw SQL or PHP that can tell what number was reached?
I'll probably just assume that its so unlikely to happen (its a very small messageboard atm) that its not worth worrying about - thanks for your help tho.
Should work ok for you. Sure, other RDBMS have different methods and options, start at value, increment value,generated by default, cache X # of IDs. The main concern is that each ID be unique, whether using an autonumber(Identity) field or a sequence object; otherwise the whole think falls apart...