472,142 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

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 3701

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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.