List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:February 21 2003 1:44am
Subject:Re: Retrieving value of auto_increment field from SQL at time of
insert
View as plain text  
At 22:45 +0200 2/20/03, Dubery wrote:
>Hi all,
>
>I have a table that includes an auto_increment field.
>
>This is used to build up an audit trail of the passage of a file through my
>server. As a file is received from a remote system I create the first entry
>for that file in the audit trail table. I build up an sql INSERT command
>(I'm
>updating the table using Perl and DBI) using information about the file -
>it's name, the IP address of the sending machine and so on.
>
>What I want to do is immediately retrieve or otherwise have returned to my
>perl program the value of the auto increment field for the newly added row.

Either user $dbh->{mysql_insertid} after issuing the insert, or
issue a SELECT LAST_INSERT_ID() query and retrieve the result.

>
>It is possible (indeed likely) that multiple processes might be updating the
>table at the same time.

Doesn't matter. That's not an issue.

>
>Thanks
>
>Bob

Thread
Retrieving value of auto_increment field from SQL at time of insertDubery20 Feb
  • RE: Retrieving value of auto_increment field from SQL at time of insertJohn W. Holmes21 Feb
  • Re: Retrieving value of auto_increment field from SQL at time ofinsertPaul DuBois21 Feb