sub add_foo { my ($bar, $blah) = @_; my $sth = $dbh->prepare('INSERT INTO foo SET ' . "bar = isnull(?, 'default_bar'), " . "blah = isnull(?, 'default_blah')) " or die "Couldn't prepare statement: " . $dbh->errstr; $sth->execute($bar, $blah) or die "Couldn't execute statement: " . $sth->errstr; my $id = $dbh->last_insert_id(undef, undef, qw(foo id)) or die "no insert id?"; return $id; }