List:MySQL and Perl« Previous MessageNext Message »
From:Michael R Boudreau Date:March 31 2009 4:26pm
Subject:Re: Trying to get the last inserted ID
View as plain text  
According to "Programming the Perl DBI" (O'Reilly 2000), the syntax varies depending on
your version of DBD::mysql:

If you used a prepare/execute:

$sth->{mysql_insertid}  (1.21_xx)
$sth->{insertid} (1.20_xx)

If you used $dbh->do:

$dbh->{mysql_insertid}  (1.21_xx)
$dbh->do("SELECT LAST_INSERT_ID()")  (1.20_xx)


On 3/31/09 10:49 AM, "Vance E. Neff" <veneff@stripped> wrote:

Hello,

I have inserted a new row into a table that has an auto incrementing key.

For some reason, I don't seem to be able to retrieve it after it is created.
I tried these two statements:
$LoginID = $dbh->last_insert_id( "", "", "Logins", "LoginID" );
and
$LoginID = $dbh->{'mysql_insertid'};

in both cases, $LoginID comes back undefined.
I tried before the COMMIT and after with the same results.  Note that
auto commit is currently turned on, so my commits should have anything
to do with anything.

What am I doing wrong?

Note that I have verified that the key is being created with the
expected values.

Vance



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/perl?unsub=1




--
Michael R. Boudreau
Senior Publishing Technology Analyst
The University of Chicago Press
1427 E. 60th Street
Chicago, IL 60637
(773) 753-3298    fax: (773) 753-3383


Thread
Can't connect to local host MySQL databaseVance E. Neff28 Mar
Re: Can't connect to local host MySQL databaseVance E. Neff29 Mar
Re: Can't connect to local host MySQL databaseMr Greg Meckes29 Mar
Re: Can't connect to local host MySQL databaseVance E. Neff30 Mar
  • Trying to get the last inserted IDVance E. Neff31 Mar
    • Re: Trying to get the last inserted IDMichael R Boudreau31 Mar