473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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_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($@){$dbh->disconnect;&error("Database error $@");exit;}
else {$sth->execute; }
return ($sth);
}

foreach $x(@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(@xs){
$SQL = "INSERT INTO articles VALUES ('ID','$x')";
&my_sql;
}
$sth->finish;
$dbh->disconnect;

Sep 6 '06 #1
0 3790

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rodrigo | last post by:
Hi all, I created a script that query a Database in mysql. Everything goes right except the fact that the results for various queries are the same. I use $sth->finish() and $dbh->disconnect()...
0
by: Nachiketh | last post by:
hi, am a newbie for internet programming and i wrote a perl script to acess a mysql database on linux... but once i tried viewing the output in a browser.. i was shown an error page... which...
1
by: Cern | last post by:
Is it somebody out there who has made a migration from an Oracle server to an MySQL server?? The scenario is as simply: I've got a Oracle 8 server with a database with content that I want to...
6
by: Taxi Driver | last post by:
Hi Everyone - Can I get your help with this, it is driving me crazy. I have 2 arrays listed below: @req=75 @req=76 @req=77 @req=78 --- @bid=75 @bid=76
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
3
by: das | last post by:
Hi all I am working in Perl from last three months;but using DBI module first time. While accessing Oracle DB through Perl I got a problem given below..... when give SQL statement in mysql it is...
4
by: jonniethecodeprince | last post by:
Greetings all. I have a problem with PERL and SQL Server. I need to upload a database query to a web page using PERL and SQL Server. I have tried to do this myself but nothing displays on the...
1
by: vignesh1985 | last post by:
hi, can u please explain how to retrieve two colums of data from two different mysql table using perl with example. thank u
11
by: gautamga | last post by:
Hi All i have created the script which calls method from other script lib and while executing i get and error Can't call method "prepare" on an undefined value at...
2
by: smithji | last post by:
Hi All, I'm having a problem executing a MySQL query witihin Perl and was hoping that someone will be able to help me in my moment of stress. When I run the below script I get this...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.