Look at mod-perl for consistant connections. You must be using apache
though.
The way you would reprepare is by having a query that might run mulitple
times but with different parameters. Here is an example...
$sth = $dbh->prepare("select col1, col2, col3 from foo where col1 = ? and
col2 = ?");
for (1..10)
{
$sth->execute($_, $_);
while((@rows) = $sth->fetchrow_array())
{
print map {print $_;} @rows;
}
}
-----Original Message-----
From: David Humpherys [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 02, 2001 9:56 PM
To: [EMAIL PROTECTED]
Subject: connect calls and optimizations
I've only been using DBI for about a week, so forgive the newbie questions.
I'm using cgi-lib and a sql database.
I have a few functions right now to handle my database stuff..(insert,
select, update).
At the beginning of each of these functions, I'm connecting to the DB and at
the end i disconnect.
I'm curious if there is a better way to do this. Because the user will be
clicking many links that re-organize the db it seems a waist to continually
re-connect to it. However, I don't know of a way (unless i have a logout
button) to know when the user is done with the page.
Also, I read that it's more efficient to prepare your statement once, and
use the bind values. However, i don't understand how this is possible if
the first time you are doing a SELECT, and the next time a INSERT. Can I
assign another $sth variable.? I'm creating a big string to evaluate based
on different parameter each time, and I don't understand how to avoid this.
Any suggestions and comments would be greatly appreciated.
David