Home > Archive > PERL Miscellaneous > April 2007 > [2] SQL error .... Can anyone tell me what's going wrong please??
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[2] SQL error .... Can anyone tell me what's going wrong please??
|
|
| Richard 2007-04-25, 7:02 pm |
| Having followed advice from my previous post, I now get the following
specific error:-
Can't call method "prepare" on an undefined value at search.pl line 283.
This seems to be on the following
$PageID = $rootkeys{$FILE};
$pagttl = ' ';
<....some omitted lines....>
my $sth = $dbh->prepare(qq{select title from pages where PageID =
$PageID});
the next 3 statements which the script doesn't get to are:-
$sth->execute();
($pagttl) = $sth->fetchrow_array();
$sth->finish();
I've put use CGI::Carp 'fatalsToBrowser'; up front, and an "or die..."
clause on the connect statement. So I assume that the connection went ok.
So what's the problem?
Or *how* do I go about finding the cause of the problem?
Many thanks...
| |
| Ignoramus13980 2007-04-25, 10:01 pm |
| On Thu, 26 Apr 2007 00:51:32 +0100, Richard <> wrote:
> Having followed advice from my previous post, I now get the following
> specific error:-
>
> Can't call method "prepare" on an undefined value at search.pl line 283.
your $dbh seems to be undefined value.
i
>
> This seems to be on the following
> $PageID = $rootkeys{$FILE};
> $pagttl = ' ';
><....some omitted lines....>
> my $sth = $dbh->prepare(qq{select title from pages where PageID =
> $PageID});
>
> the next 3 statements which the script doesn't get to are:-
> $sth->execute();
> ($pagttl) = $sth->fetchrow_array();
> $sth->finish();
>
> I've put use CGI::Carp 'fatalsToBrowser'; up front, and an "or die..."
> clause on the connect statement. So I assume that the connection went ok.
> So what's the problem?
>
> Or *how* do I go about finding the cause of the problem?
>
> Many thanks...
>
>
>
| |
| Joe Smith 2007-04-26, 7:03 pm |
| Richard wrote:
> So I assume that the connection went ok.
That's an unfounded assumption.
> So what's the problem?
> Or *how* do I go about finding the cause of the problem?
Check that all function and method calls have indicated success.
> my $sth = $dbh->prepare(qq{select title from pages where PageID = $PageID});
# Put this in front of the prepare() statement:
unless ($dbh) {
die "Unable to create a DB handle. The error message is ",...;
}
# Put this after the prepare() and before the execute():
unless ($sth) {
die "Unable to create STH for $dbh (PageID=$PageID). The error is ",...;
}
You'll need to expand the ... parts to retrieve the error messages.
-Joe
| |
|
|
|
|
|