Last_Insert_ID

Last_Insert_ID

am 14.06.2004 12:01:36 von Scott Simpson

------=_NextPart_000_000A_01C451FE.F6806850
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Dear All,

I am working with an older version 3.23.54 of MySQL. I have a subroutine
like this:

sub c_new
{
my ($dbh, $params) = @_;
my $query = qq{INSERT INTO t_masts (f_site, f_name) VALUES
('$params->{f_site}', '$params->{f_name}')};
my $sth = $dbh->prepare(qq{$query});
$sth->execute();
$query = qq{SELECT LAST_INSERT_ID() from t_masts};
$sth = $dbh->prepare(qq{$query});
my $last_id = $sth->execute();
$sth->finish();
return $last_id;
}

Which returns the ID of the last record inserted into t_masts. Except that
after deleting record(s) from t_masts the subroutine returns the number of
records in t_masts (which is less than the ID of the record inserted and
it's that ID I want). My reading of the DuBois's book is that this should
work in version 3.23 upward.

Can anyone point out what I have missed?

Regards,
Scott


------=_NextPart_000_000A_01C451FE.F6806850--