new dbi connection for each request under mod_perl

D

david

Hi all,

I have an application that i want to move to mod_perl.
My problem is that under the application i have a class variable that
makes caching of the database handler of dbi
This is how the class looks like
package Connection;
use DBI;

my $dbh;

sub instance {
if (!$dbh) {
$dbh = DBI->new;
}
return $dbh;
}

Before it was nice, because if in the same request i wanted to get
more than one connection it returned me the same.
But here in mod_perl i get for different requests the same dbh and the
application relies that it won't be the connection. For example, i
create temporary tables that are deleted automatically after each
request, because the connection expires, but now not.
What is the solution for this problem ?

Thanks in advance,
David
 
D

david

This sentence is unfinished.







That sentence is difficult to parse, but I think you're saying that you
get the same $dbh for different requests, and you don't want that.



You say you're moving the application to mod_perl, but you didn't say
what you're moving it from--normal CGI? Are you using Registry scripts
or Perlrun?

Anyway, do this search:http://search.aol.com/aol/search?s_it=topsearchbox.search&q=mod+perl+END

The second result shows how to use register_cleanup().

I wanted to move a normal cgi to mod_perl.
Thanks a lot for the link
 
X

Xho Jingleheimerschmidt

david said:
Hi all,

I have an application that i want to move to mod_perl.

Why do you want to move? Usually you move an application to mod_perl in
order to make it faster. And often an important part of making it
faster is to cache database handles across invocations, rather than
repeatedly creating them anew.

....
application relies that it won't be the connection. For example, i
create temporary tables that are deleted automatically after each
request, because the connection expires, but now not.
What is the solution for this problem ?

Does the DBMS you are using have an option that temporary tables be
dropped at the end of a transaction, rather than the end of a session?


Xho
 
T

Ted Zlatanov

d> Hi all,
d> I have an application that i want to move to mod_perl.
d> My problem is that under the application i have a class variable that
d> makes caching of the database handler of dbi
d> This is how the class looks like
d> package Connection;
d> use DBI;

d> my $dbh;

d> sub instance {
d> if (!$dbh) {
d> $dbh = DBI->new;
d> }
d> return $dbh;
d> }

d> Before it was nice, because if in the same request i wanted to get
d> more than one connection it returned me the same.
d> But here in mod_perl i get for different requests the same dbh and the
d> application relies that it won't be the connection. For example, i
d> create temporary tables that are deleted automatically after each
d> request, because the connection expires, but now not.
d> What is the solution for this problem ?

I think (I'm not able to parse your message 100%) you want to use
Apache::DBI. No caching needed.

http://search.cpan.org/~abh/Apache-DBI/

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top