Page 1 of 1

[solved] return current row auto_increment value on insert?

Posted: Tue Feb 20, 2007 3:01 pm
by Skara
example table:

id, int, auto_inc, primary key
data1, int
data2, varchar
...etc

Can I get the value of `id` when I insert a row somehow? Here's what I've currently got (basically):

Code: Select all

INSERT INTO `table` VALUES('','abc','def','ghi');
SELECT `id` FROM `table` WHERE `data1`='abc' AND `data2`='def' AND `data3`='ghi' LIMIT 1;
--there won't be any duplicate entries, so this /should/ work, but..

I'd LIKE to do something like...

Code: Select all

INSERT INTO `table` VALUES('','abc','def','ghi') AND SELECT `id` FROM {this};
Is something like that possible?

Posted: Tue Feb 20, 2007 4:05 pm
by feyd

Code: Select all

SELECT LAST_INSERT_ID()
or mysql_insert_id() maybe?

Posted: Tue Feb 20, 2007 4:45 pm
by Skara
aha! Thanks!