Re: Trying to get the last inserted ID
Michael R Boudreau <[email protected]> Tue, 31 Mar 2009 11:26:45 -0500
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <C5F7AE75.17EB4%[email protected]> |
--_000_C5F7AE7517EB4mboudreaaduchicagoedu_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
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" <[email protected]> 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 =3D $dbh->last_insert_id( "", "", "Logins", "LoginID" );
and
$LoginID =3D $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/[email protected]=
cago.edu
--
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
--_000_C5F7AE7517EB4mboudreaaduchicagoedu_--