| Which row did I just insert?
|
webfoo

msg:4325738 | 1:26 am on Jun 14, 2011 (gmt 0) | I created a PHP file to insert a new record into a database. The table's ID field is set to auto increment. Multiple users may be inserting rows simultaneously, so the highest ID is not a good indicator for which row I just inserted. How can I get the ID from the row I just inserted?
|
webfoo

msg:4325740 | 1:32 am on Jun 14, 2011 (gmt 0) | NM. [w3schools.com...]
|
coopster

msg:4325900 | 1:02 pm on Jun 14, 2011 (gmt 0) | Yep, LAST_INSERT_ID(). [dev.mysql.com...]
|
rocknbil

msg:4326027 | 4:57 pm on Jun 14, 2011 (gmt 0) | Yeah but make sure you get via last insert id immediately after doing the insert . . . I always use a new select with the unique data I just inserted to make sure it's the relevant record. Select id from table where email='inserted@email.com' and user_id=12345; It's always a **very good idea** to use a second field for user_id or other unique id rather than the auto increment field.
|
|
|