$dbh = DBI->connect("dbi:mysql:database=$db_name;host=$ip;port=3306",$user,$passwd,{
RaiseError => 1,
AutoCommit => 0
}) or die "can't connect to database ". DBI-errstr;
eval{
$dbh->do("select count(*) from t1 for update") ;
$dbh->do("insert into t1 values(87)") ;
$dbh->commit;
};
if( $@ ) {
#warn "Database error: $DBI::errstr\n";
$dbh->rollback(); #just die if rollback is failing
};
$dbh->disconnect;
转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199329.html