Apologies for the slightly misleading title I didn't know how to succinctly describe my problem. I would like to get the details, specifically primary key, of the row I have just inserted. I could quite easily check the last inserted row AFTER I have inserted it, but what would happen if another row was added before I did that? Does anyone know how to do this? Thanks
You can use mysql_insert_id() to retrieve the id of the last inserted row - http://us.php.net/mysql_insert_id. As long as you are using the same connection there's no chance of retrieving the wrong row regardless of what else is happening at the same time.
for mysql I think it's get_last_rowid() That will give you the last row id of that txn. If another process does an insert in the mean time it will still return that txn id that was inserted.
You only work with your own session. If anyone add another row to the database before you retrieve your last row id, it doesn't affect you. You can still retrieve your last row id. I assume you use something like mysql_insert_id() to retrieve your last insert row ID.
Thanks guys, appreciate the replies. Out of interest, if the page gets called twice as the same time, will it process them sequentially then, or in parallel? I assumed parallel hence my worry about getting the last ID.
Should still work fine. The last_id is retrieved based on the connection being used. A single script could make an insert and then retrieve the correct id even if the script took five minutes to process between the insert and the retrieval. Not positive on this, but if you are using a singleton pattern for your database connection, then it may be possible to get an incorrect id.