[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: Can't call method "prepare" on an undefined value
From:       "Kevin Field" <kev () brantaero ! com>
Date:       2007-07-23 12:16:38
Message-ID: 2008368801-BeMail () Kev
[Download RAW message or body]

> > My code around line 1059 in MySQLBroker.pm looks like this:
> >
> > sub _mysql_exec {
> >   my ($self, $dbcall) = @_;
> >   my @resultsArray;
> >   my $count=0;
> >   my $sth = $self->{_dbh}->prepare("$dbcall");
> 
> You shouldn't store a $dbh in your objects like this.  Apache::DBI
> will check that your connection is still good when you try to use it,
> but only if you call connect().  If you don't, your connection can go
> stale and get dropped.

Aside from that, a general trick that seems to help sometimes is 
changing "my" to "local our".  But I believe Perrin is right, you 
should have your scripts call connect() at their beginnings, and 
Apache::DBI will do the caching for you.

Kev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic