best may to use $dbh->disconnect; and $sth->finish;

Please advise, I have the following example and want to know the best
way to use $dbh->disconnect; and $sth->finish;

--------------
$sql_host="localhost";
$sql_dataname = "database";
$sql_userid = "root";
$sql_password = "password";

&connect_sql;

sub connect_sql{
use DBI;
$DSN = "DBI:mysql:$sql_dataname:$sql_host";
$dbh = DBI->connect($DSN,$sql_userid,$sql_password)
|| &error("Database connection failed: $DBI::errstr") unless $dbh;
return;
}

sub my_sql{
eval{ $sth = $dbh->prepare($SQL); };
if($ [at] ){$dbh->disconnect;&error("Database error $ [at] ");exit;}
else {$sth->execute; }
return ($sth);
}

foreach $x( [at] xs){
$SQL = "INSERT INTO articles VALUES ('ID','$x')";
&my_sql;
$sth->finish;
}

$dbh->disconnect;

or is it better to put $sth->finish; out of the loop above? like

foreach $x( [at] xs){
$SQL = "INSERT INTO articles VALUES ('ID','$x')";
&my_sql;
}
$sth->finish;
$dbh->disconnect;
mamod20 [ Mi, 06 September 2006 13:33 ] [ ID #1456929 ]
Datenbanken » mailing.database.mysql » best may to use $dbh->disconnect; and $sth->finish;

Vorheriges Thema: How to recover deleted rows
Nächstes Thema: Query issues - works manually... doesn't with mysql_real_query