You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Vladimir S. Tikhonjuk" <vs...@vst.donetsk.ua> on 2006/10/02 19:57:23 UTC

Apache::DBI and pnotes

    Hi all!
    I have some simple scripts, on my web server. Each of them have to
do some tasks with database, so the first what I do in the handler is:

my $database_connect = DBI->connect(
 'dbi:Pg:dbname=$database;host=$host,
    $user,
    $password
  ) || die "Can't connect to database: ".$DBI::errstr;

    As I understand, I may write a handler, which would have such code,
and then use pnotes to export $database_connect variable to other handlers.
    Could anyone give me any example of such tasks ?

Best regards,
Vladimir S. Tikhonjuk

Re: Apache::DBI and pnotes

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Oct 2, 2006, at 5:31 PM, Michael Peters wrote:
>> does apache::dbi ping a connection then reconnect if the ping fails?
>
> If you call DBI->connect it does.

awesome.  i never knew that.

Re: Apache::DBI and pnotes

Posted by Michael Peters <mp...@plusthree.com>.

Jonathan Vanasco wrote:
> 
> On Oct 2, 2006, at 4:01 PM, Michael Peters wrote:
> 
>> The main problem with this is that if you loose your db connection
>> somehow, you
>> wouldn't know until it bombed out on you unless you constantly check it
>> everytime before you use it.
> 
> does apache::dbi ping a connection then reconnect if the ping fails?

If you call DBI->connect it does.

-- 
Michael Peters
Developer
Plus Three, LP


Re: Apache::DBI and pnotes

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Oct 2, 2006, at 4:01 PM, Michael Peters wrote:

> The main problem with this is that if you loose your db connection  
> somehow, you
> wouldn't know until it bombed out on you unless you constantly  
> check it
> everytime before you use it.

does apache::dbi ping a connection then reconnect if the ping fails?



Re: Apache::DBI and pnotes

Posted by Michael Peters <mp...@plusthree.com>.

Jonathan Vanasco wrote:

> but storing pnotes is just
> 
> handler 1
>     $r->pnotes( 'database_connect'=> $database_connect );
> 
> handler 2
>     my     $database_connect = $r->pnotes('database_connect');

The main problem with this is that if you loose your db connection somehow, you
wouldn't know until it bombed out on you unless you constantly check it
everytime before you use it.

If you create a simple sub in your handler (or handler base class if you use
multiple handlers) that calls DBI->connect() and use Apache::DBI, it will take
care of all that checking for you and make sure you have a connection (if one
can be made).

-- 
Michael Peters
Developer
Plus Three, LP


Re: Apache::DBI and pnotes

Posted by Jonathan Vanasco <mo...@2xlp.com>.
On Oct 2, 2006, at 1:57 PM, Vladimir S. Tikhonjuk wrote:

> my $database_connect = DBI->connect(
>  'dbi:Pg:dbname=$database;host=$host,
>     $user,
>     $password
>   ) || die "Can't connect to database: ".$DBI::errstr;
>
>     As I understand, I may write a handler, which would have such  
> code,
> and then use pnotes to export $database_connect variable to other  
> handlers.
>     Could anyone give me any example of such tasks ?


if you are using apache::dbi, you can just repeatedly call connect--  
apache::dbi will catch the connect and just toss you back the  
existing connection

===
but storing pnotes is just

handler 1
	$r->pnotes( 'database_connect'=> $database_connect );

handler 2
	my 	$database_connect = $r->pnotes('database_connect');