finish()
$sth->finish()This method ends a statement handle given that was
established by the prepare() method. There
are no arguments to the method. It can sometimes help to free system
resources. It should be issued only when the statement handle is not
going to be reused or is to be replaced. Here is an example:
...
my $sql_stmnt = "REPLACE INTO books (title, author)
VALUES(?,?)";
my $sth = $dbh->prepare($sql_stmnt);
while( my ($title,$author) = each(%books) ) {
$sth->execute($title,$author);
}
$sth->finish();
$dbh->disconnect();Since we’re reusing the statement handle here (assuming
%books defined earlier in the program has plenty of
data), we especially don’t need to call the
finish() method after each execution of the
SQL statement. Although a statement handle may have been closed with
finish(), more statement handles may be
created and executed as long as the database handle has not been
closed using disconnect().