in reply to DBI sudden exit on MySQL insert

i can't answer your question, but i recommend you check for errors from prepare as well. (one possibility is that one of your keys is not a column of $table, but i would expect to see an error trying to call execute on an undefined value.)
my $sth = $dbh->prepare($sqlstatement) or die "cannot prepare: $DBI::errstr";
unrelated, but you can also simplify the top part of your function a bit:
my @values = values %$data; my $keylist = join ',', keys %$data; my $qlist = join ',', ('?') x @values;