end0tknr's kipple - 新web写経開発

http://d.hatena.ne.jp/end0tknr/ から移転します

perlで mysqlのauto_incrementの値を確認するには、mysql_insertid

sub add_auto_increment_record {
    my ($self,$dbh) = @_;

    my $sql =<<EOF;
insert into test_table (key, val) values (?, ?)
EOF
    my $sth = $dbh->prepare($sql);
    my @vals = ('FOO','BAA');
    unless($sth->execute(@vals)){
        $self->error( $sth->errstr );
        return undef;
    }
    return $sth->{mysql_insertid};
}