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
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.