perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Xinhuan Zheng <xzh...@christianbook.com>
Subject Re: Apache::DBI connect
Date Mon, 11 Nov 2013 15:01:49 GMT
Hi Perrin,

Thanks very much for below information. This is helpful. My conclusion is that there is no
problem in Apache::DBI. It is the application code that doesn't handle db connection correctly.

- xinhuan

From: Perrin Harkins <pharkins@gmail.com<mailto:pharkins@gmail.com>>
Date: Monday, November 11, 2013 9:57 AM
To: Xinhuan Zheng <xzheng@christianbook.com<mailto:xzheng@christianbook.com>>
Cc: Adam Prime <adam.prime@utoronto.ca<mailto:adam.prime@utoronto.ca>>, "modperl@perl.apache.org<mailto:modperl@perl.apache.org>"
<modperl@perl.apache.org<mailto:modperl@perl.apache.org>>
Subject: Re: Apache::DBI connect


On Fri, Nov 8, 2013 at 2:58 PM, Xinhuan Zheng <xzheng@christianbook.com<mailto:xzheng@christianbook.com>>
wrote:
The query is from the application code not the 'select 1' test query.

OK, then it seems like Apache::DBI may not have a problem.

While most of time I saw Apache::DBI->connect is called but sometime from a process, it
will print out it finds a cached connection and ping is ok but sometimes from the same process
it didn't find a cached connection. Since it's the same process, it doesn't make sense it
can find a cached one then it didn't find any. Even after it says it didn't find a cached
one then after that it prints out it still has a cached one and can use that one. It sounds
like in same process sometimes the Apache:DBI connection cache can be accessed but sometimes
it cannot.

The cache can always be accessed.  It's just a hash in a global variable.  There are a couple
of possible explanations for what you're seeing, off the top of my head.  One is that you
might be sending in slightly different connection parameters, which means you can't use the
cached connection.  Another is that your code might not be calling DBI->connect() or DBI->connect_cached().

The base class is similar to a class in Java world. Basically it has set and get methods.
Among other things, it sets $db and gets $db. The class has its own fetch method and it'll
use $self->db method call to do the fetch/insert,etc.

It's ok to keep a database handle during the length of one request, but you shouldn't keep
it in your own global between requests, so if objects of this class stay around for longer
than one request you should not store a db handle in them.  The safest thing would be for
your $self->db() method to just call DBI->connect_cached() every time.

BTW, the class has a method AUTOLOAD, although I don't quite understand how AUTOLOAD works.

There's a lot of good documentation on AUTOLOAD in the Perl man pages and books.  It's not
relevant to your database issues though.

- Perrin

Mime
View raw message