in reply to How do I find the value MYSQL assigned to an AUTO_INCREMENT ID (int) Field?
From the Giving Credit where Credit is Due department: I got this from this link.#!/usr/bin/perl # connect to database .... my $sql_statement = "INSERT INTO $table (field1,field2) VALUES($value1,$value2)"; my $sth = $dbh->prepare($sql_statement); $sth->execute or die "Can't Add record : $dbh->errstr"; # Now we can retrieve the primary key that # was just created in our last insert. my $table_key = $sth->{insertid}; # or you could use this method which # is DBI-standard my $table_key = $dbh->{'mysql_insertid'}; $sth->finish;
|
|---|