Re: prob with PERL/Postgres

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Good <tomg(at)admin(dot)nrnet(dot)org>
Cc: Kate Collins <klcollins(at)wsicorp(dot)com>, kris(at)grinz(dot)com, pgsql-sql(at)postgresql(dot)org
Subject: Re: prob with PERL/Postgres
Date: 2001-08-06 21:39:15
Message-ID: 24707.997133955@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thomas Good <tomg(at)admin(dot)nrnet(dot)org> writes:
> Kate, he uses a diff module by the same author (Edmund Mergl) but with
> a very diff syntax. The advantage of the DBI - Kris, if you're
> interested - is that the syntax is much like ESQL/C and the code is
> much more portable. For example I use DBI to access both pg and
> oracle.

DBI is a good alternative, but is unlikely to act much differently as
far as connection problems go.

> use Pg;
> $dbhost='127.0.0.1';
> $dbname='mpact';
> #$connstr="dbname=$dbname";
> $connstr="host=$dbhost dbname=$dbname";
> $conn = Pg::connectdb($connstr);
>
> #more code related to date omitted
>
> $result=$conn->exec($sql);
> (PGRES_COMMAND_OK eq $result->resultStatus)
> or die $conn->errorMessage;
>
> WHY DO I GET PQsendQuery() -- There is no connection to the
> backend.

It's hard to tell with only that much information. I think the real
mistake in this code is not checking for failure of the connectdb()
call. Had you checked at that point, you would have gotten a more
useful error message. The examples in the Pg documentation recommend

$conn = Pg::connectdb(whatever);
die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;

Try that, and if you're still in the dark, let us see the error
message...

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-08-06 21:50:20 Re: Re: Data type confusion
Previous Message Thomas Good 2001-08-06 21:14:50 Re: prob with PERL/Postgres