Jump to content

[SOLVED] Fetch auto-incremented index ID while the row is being created


Recommended Posts

I've been having a hard time finding this because I'm not sure how to ask it succinctly.

 

Basically, I'm entering new data rows into a database, but I then need to retrieve the auto-incremented primary key for use immediately after. I can't know what the key will be before I create the row (that I'm aware of), so I was wondering if there was anything I could do to retrieve that value without creating and running a separate query.

as a note: mysql_insert_id() MUST be called immediately after the insert query, even if the only other query run was not an insert. It will return 0 otherwise, rather than the insert id.

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.