Skip to content

Instantly share code, notes, and snippets.

@ktat
Last active June 11, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktat/69072d306e3916ea1d41ba8333e5d3c7 to your computer and use it in GitHub Desktop.
Save ktat/69072d306e3916ea1d41ba8333e5d3c7 to your computer and use it in GitHub Desktop.
DBD::mysql mysql_insertid returns 0
## version
# Perl 5.18.1
# DBI 1.636
# DBD::mysql 4.033
## create table SQL
# create table t(id integer not null auto_increment, primary key (id)) ;
## this can get mysql_insertid
my $dbh = DBI->connect("dbi:mysql:test;user=root");
my $sth = $dbh->prepare("insert into t() values()");
$sth->execute();
print $dbh->{mysql_insertid}
## use ping method before getting mysql_isnertid, mysql_insertid returns 0
my $dbh = DBI->connect("dbi:mysql:test;user=root");
my $sth = $dbh->prepare("insert into t() values()");
$sth->execute();
$dbh->ping;
print $dbh->{mysql_insertid}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment