clamum
Lifer
I am inserting some data into a MySQL database with the standard INSERT statement. One of the fields in the table is a customer_id field, with an auto incrementing id.
After inserting the record successfully, I would like to retreive that customer_id to use in a subsequent INSERT statement.
Right now I'm doing a SELECT statement which matches every other field except the id field to find the just added record... however this could technically fail because a record could have all the same values except that customer_id field (which is the primary key).
So, any ideas on how I could do this? While typing out this post I thought I could find the largest customer_id in the table (since it's auto incrementing) after the first INSERT operation and that should be the one that was just inserted. But it is possible that a record could have been inserted in this time I suppose... though the website this is for is not a high traffic site, so I may be safe.
After inserting the record successfully, I would like to retreive that customer_id to use in a subsequent INSERT statement.
Right now I'm doing a SELECT statement which matches every other field except the id field to find the just added record... however this could technically fail because a record could have all the same values except that customer_id field (which is the primary key).
So, any ideas on how I could do this? While typing out this post I thought I could find the largest customer_id in the table (since it's auto incrementing) after the first INSERT operation and that should be the one that was just inserted. But it is possible that a record could have been inserted in this time I suppose... though the website this is for is not a high traffic site, so I may be safe.