CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Maintaining the database connection

 



sdaithankar
Deleted

Jan 11, 2001, 12:49 PM

Post #1 of 5 (1112 views)
Maintaining the database connection Can't Post

Hi,

I have the script say (a.pl) in which i am using
USE DBI
$dbh = DBI->connect('dbi:Oracle:'test','te1','te2')
and i am making the database connection.

Every time the user requests some query its going through
a.pl and makes the database connection and then goes to specified routine forexample search.
Like a.pl?search

But in this process everytime its making the connection with datatabase.
How can i mantain the database connection? I mean how can i use the same same database handle.

Any ideas?

Thanks






Jasmine
Administrator / Moderator

Jan 15, 2001, 3:57 PM

Post #2 of 5 (1089 views)
Re: Maintaining the database connection [In reply to] Can't Post

If you have the program connecting when a query is made, it sounds like it may be a scoping issue. Without seeing the code, if you're using

sub connect {
my $dbh = DBI->connect('dbi:Oracle:'test','te1','te2')
}

Once connect finished the subroutine, $dbh has gone out of scope and the connection will terminate. If you return $dbh, however, it will stay alive:

my $handle = connect();
my $searchresults = search($handle);

sub connect {
my $dbh = DBI->connect('dbi:Oracle:'test','te1','te2')
return $dbh;
}

sub search {
my $dbh = shift;
my $query = $dbh->prepare("select statement here");
$query->execute() or die $dbh::errstr;
# etc...
}

Hope this helps!



sdaithankar
Deleted

Jan 16, 2001, 12:49 PM

Post #3 of 5 (1081 views)
Re: Maintaining the database connection [In reply to] Can't Post

thanks



sdaithankar
Deleted

Jan 16, 2001, 12:56 PM

Post #4 of 5 (1080 views)
Re: Maintaining the database connection [In reply to] Can't Post

Jasmine: Thanks,
Now lets consider the code you wrote is in single Per
Programme " J_test.pl"
my $handle = connect();
my $searchresults = search($handle);

sub connect {
my $dbh = DBI->connect('dbi:Oracle:'test','te1','te2')
return $dbh;
}

sub search {
my $dbh = shift;
my $query = $dbh->prepare("select statement here");
$query->execute() or die $dbh::errstr;
# etc...
}

So, If I call the "J_test.pl" again, It will make the Connection to database again I think making the Conncetion is resource consuming.
I do not want to connect it again. But i want to use
the same database connection.
In short, I donot want to call the routine Connect again.
Any ideas?

Thanks again.
Sanjeev





Jasmine
Administrator / Moderator

Jan 16, 2001, 1:20 PM

Post #5 of 5 (1078 views)
Re: Maintaining the database connection [In reply to] Can't Post

As far as I'm aware, there's no way to persistently keep data connections open.

You may want to check out the DBI::Oracle readme files at http://theoryx5.uwinnipeg.ca/CPAN/data/DBD-Oracle/


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives