stevieontario Posted May 27, 2009 Share Posted May 27, 2009 Good morning PHP Freaks: I'm curious about the difference between the two functions Mysql_insert_id and last_insert_id. Other than that the first is a PHP function and the second belongs to MySql, they both appear to do the same thing, which is to get the most recently generated auto-incremented value. If that is the case, which is the better one to use? The reason I ask: I have a Table1 which updates hourly (i.e., adds a new row every hour) and a Table2 which contains hourly production data on roughly 100 machines. Table1's id is an auto-incremented field (and the primary key). I want Table2 to hold a column with Table1's id, so that every hour Table2 will get 100 or so new rows with the same Table1 id. This way, I can query production data over time and date ranges. Any ideas/suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/159892-mysql_insert_id-versus-last_insert_id/ Share on other sites More sharing options...
fenway Posted June 2, 2009 Share Posted June 2, 2009 Other than that the first is a PHP function and the second belongs to MySql, they both appear to do the same thing, which is to get the most recently generated auto-incremented value. That's correct -- there's no difference whatsoever, the php function is simply a wrapper. Quote Link to comment https://forums.phpfreaks.com/topic/159892-mysql_insert_id-versus-last_insert_id/#findComment-847727 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.