469,933 Members | 2,015 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,933 developers. It's quick & easy.

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_dataname = "database";
$sql_userid = "root";
$sql_password = "password";


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;

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

foreach $x(@xs){
$SQL = "INSERT INTO articles VALUES ('ID','$x')";


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

foreach $x(@xs){
$SQL = "INSERT INTO articles VALUES ('ID','$x')";

Sep 6 '06 #1
0 3632

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rodrigo | last post: by
reply views Thread by Nachiketh | last post: by
6 posts views Thread by Taxi Driver | last post: by
3 posts views Thread by das | last post: by
1 post views Thread by vignesh1985 | last post: by
2 posts views Thread by smithji | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.