10legit10quit Posted August 3, 2007 Share Posted August 3, 2007 Have a quick question about PHP & SQL: is there any way to find info of a newly inserted record? For example a record is being inserted with no value for a timestamp field, so it is filled automatically when the record is inserted. Is there any way to quickly retrieve this entry information? I'm not sure if "Select last_insert_id" will work properly, because with multiple users it is possible that anther record has been inserted already. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/63212-solved-retrieve-newly-inserted-record/ Share on other sites More sharing options...
roopurt18 Posted August 3, 2007 Share Posted August 3, 2007 Unless I'm mistaken, if the users are on different connections to the DB then last_insert_id will return the ID for the user calling it and not other users. Quote Link to comment https://forums.phpfreaks.com/topic/63212-solved-retrieve-newly-inserted-record/#findComment-315083 Share on other sites More sharing options...
10legit10quit Posted August 3, 2007 Author Share Posted August 3, 2007 Unless I'm mistaken, if the users are on different connections to the DB then last_insert_id will return the ID for the user calling it and not other users. The database is being accessed through a PHP file on the webserver, so it might be seen as just one user. Actually "mysql_insert_id();" might be the correct command to use, here is the current code. It seems to work ok but I am worried about problems with multiple users. $sql = 'INSERT INTO `TransactionHistory` (`thRef`, `thDate`, `thSenderAccount`, `thRecipientAccount`, `thSenderKey`, `thRecipientKey`, `thBalance`, `thLabel`, `thThreadNumber`, `thEnteredByForumID`, `thMemo`, `thPMemo1`, `thPMemo2`) VALUES (NULL, "' .$transDate .'", "' .$sendAccName .'", "' .$recAccName .'", "' .$sendAccKey .'", "' .$recAccKey .'", "' .$transAmt .'", "' .$transLabel .'", "' .$transThreadNum .'", "' .$enteredByID .'", "' .$transMemo .'", "' .$transPMemo1 .'", "' .$transPMemo2 .'")'; //perform query $result = mysql_query($sql); //get recent id $lastid = mysql_insert_id(); Quote Link to comment https://forums.phpfreaks.com/topic/63212-solved-retrieve-newly-inserted-record/#findComment-315089 Share on other sites More sharing options...
roopurt18 Posted August 3, 2007 Share Posted August 3, 2007 That will work correctly with multiple users. Quote Link to comment https://forums.phpfreaks.com/topic/63212-solved-retrieve-newly-inserted-record/#findComment-315136 Share on other sites More sharing options...
10legit10quit Posted August 3, 2007 Author Share Posted August 3, 2007 ok, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/63212-solved-retrieve-newly-inserted-record/#findComment-315170 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.