in reply to How do I find what column $dbh-{'insert_id'} was inserted into?

The function you need is LAST_INSERT_ID().

Immediately after the insert, execute a SELECT LAST_INSERT_ID() as if it were a normal select statement in DBI. The value you retreive will be the auto_increment column value of your recent insert.

This is covered in the DuBois book (pp. 93, 170, 547) and in the MySQL online docs under 'Miscellaneous Functions'.

(Note that mysql_insert_id() is part of the C API and is not directly accessable from Perl.)

  • Comment on Re: How do I find what column $dbh-{'insert_id'} was inserted into?

Replies are listed 'Best First'.
Re: Re: How do I find what column $dbh-{'insert_id'} was inserted into?
by boo_radley (Parson) on Feb 14, 2001 at 18:35 UTC
    The function you need is LAST_INSERT_ID().
    I think this is particular to MySQL. For Sybase and Oracle, also try
    SELECT @@IDENTITY FROM table
    My projects have always had this statement in a transaction, but I'm not sure if it's needed.