DBI: disconnect - question

sid_com picture sid_com · Mar 16, 2011 · Viewed 7.2k times · Source

Would you call parts of the disconnect-code as line-noise or would you leave it as it is?

use DBI;

my $dbh = DBI->connect ...
...
...
END {
    $dbh->disconnect or die $DBI::errstr if $dbh;
}

Answer

Eugene Yarmash picture Eugene Yarmash · Mar 16, 2011

Explicit disconnection from the database is not strictly necessary if you are exiting from your program after you have performed all the work. But it is a good idea, especially in programs in which you have performed multiple connections or will be carrying out multiple sequential connections.

See Programming the Perl DBI for more info.