Jump to content

MySql_insert_id versus last_insert_id


stevieontario

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/159892-mysql_insert_id-versus-last_insert_id/
Share on other sites

  Quote

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.