Re: $dbh->last_insert_id() support?

Paul DuBois <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <p06020400bda60ac1fb2f@[192.168.0.34]>
At 12:25 +1000 10/28/04, Daniel Kasak wrote:
>Hi all.
>
>I'm back again with the same issue as last time ... DBD::mysql 
>doesn't seem to support $dbh->last_insert_id() as advertised in the 
>DBI documentation:

For MySQL, that's my belief as well.


>
>---
>
>       "last_insert_id"
>             $rv = $dbh->last_insert_id($catalog, $schema, $table, $field);
>             $rv = $dbh->last_insert_id($catalog, $schema, $table, 
>$field, \%attr);
>
><snipped>
>
>* For some drivers the $catalog, $schema, $table, and $field 
>parameters are required (e.g., Pg), for others they are ignored 
>(e.g., mysql).
>
>---
>
>I haven't been able to sucessfully get the last inserted id from an 
>auto_increment column in this way yet:
>
>---
>
>#!/usr/bin/perl -w
>use strict;
>
>use DBI;
>use Cwd;
>
>my $dbh = DBI->connect 
>("dbi:mysql:dbname=test;host=screamer;port=3306", "some_username", 
>"somepassword", {
> 
>                                                                                         
>PrintError => 0,
> 
>                                                                                         
>RaiseError => 0,
> 
>                                                                                         
>AutoCommit => 1,
> 
>                                                                                       
>});
>
>$dbh->do("create table my_test_table ( ID mediumint not null 
>auto_increment, SomeStuff varchar(100), primary key (ID) )");
>$dbh->do("insert into my_test_table ( SomeStuff ) values ( 'Hi there!' )");
>
>my $inserted_id = $dbh->last_insert_id(undef, undef, undef, undef);
>print "According to the 'last_insert_id' method of the DBH, I 
>inserted a record with primary key: $inserted_id\n";
>
>$inserted_id = $dbh->{'mysql_insertid'};
>print "According to the 'mysql_insertid' attribute of the DBH, I 
>inserted a record with primary key: $inserted_id\n";
>
>$dbh->disconnect;
>
>---
>
>Does anyone know if the last_insert_id() method is supposed to be 
>supported for MySQL? I would *really* like to use it instead of the 
>MySQL-specific $dbh->{'mysql_insertid'};
>I'm using DBD-mysql-2.9004, which according to 
>http://search.cpan.org/dist/DBD-mysql/ is the latest stable release.
>
>Dan
>
>--
>Daniel Kasak
>IT Developer
>NUS Consulting Group
>Level 5, 77 Pacific Highway
>North Sydney, NSW, Australia 2060
>T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
>email: [email protected]
>website: http://www.nusconsulting.com.au
>
>
>--
>MySQL Perl Mailing List
>For list archives: http://lists.mysql.com/perl
>To unsubscribe:    http://lists.mysql.com/[email protected]


-- 
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.