This is a discussion on last_insert_id() within the MySQL Database forums, part of the Database Forums category; Anyone out there have a working snippet of code using last_insert_id() to grab the last inserted record id? I've ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Anyone out there have a working snippet of code using last_insert_id()
to grab the last inserted record id? I've been trying to for the last hour and get nuttin but errors so far. I'm using coldfusion too btw, I have song_id which is my PK and I can pull the ids using SELECT * just fine, but the minute I try to do last_insert_id(song_id) it bombs. I guess I'm just not understanding how to use it....seeing the proper syntax would be great if possible. TIA Bewildered Bob |
|
|||
|
>Anyone out there have a working snippet of code using last_insert_id()
>to grab the last inserted record id? Example: SELECT LAST_INSERT_ID(); OR INSERT INTO tablea (....) VALUES (....); Do the insert. INSERT INTO tableb (parent_id, detail 1, detail2) VALUES ( last_insert_id(), 'XYZ', '1234'); Refer to tablea. >I've been trying to for the last >hour and get nuttin but errors so far. I'm using coldfusion too btw, I >have song_id which is my PK and I can pull the ids using SELECT * just >fine, but the minute I try to do last_insert_id(song_id) it bombs. I Don't use an argument for last_insert_id(). I think that's mostly used for replaying binary logs from an old backup and transaction logs. Note: you don't get to select which table. It's the last inserted id for your connection (you don't have to worry about someone else doing inserts at the same time) for *any* table. If you want the id for a table you just inserted to, grab the value before doing more inserts. |
|
|||
|
Bob Imperial wrote:
> Anyone out there have a working snippet of code using last_insert_id() > to grab the last inserted record id? I've been trying to for the last > hour and get nuttin but errors so far. I'm using coldfusion too btw, I > have song_id which is my PK and I can pull the ids using SELECT * just > fine, but the minute I try to do last_insert_id(song_id) it bombs. I > guess I'm just not understanding how to use it....seeing the proper > syntax would be great if possible. > TIA > > Bewildered Bob http://dev.mysql.com/doc/refman/5.0/...functions.html Scroll down to LAST_INSERT_ID() -- Brian Wakem Email: http://homepage.ntlworld.com/b.wakem/myemail.png |