Re: Bad column offset? - Mailing list pgsql-general

From Mauricio Carvalho de Oliveira
Subject Re: Bad column offset?
Date
Msg-id 36A99BC9.C9C205A7@dt.fee.unicamp.br
Whole thread Raw
List pgsql-general
> Subject: Bad column offset ?
>
> I am porting all my applications from mSQL to PostgreSQL. I am trying to
> access the results from a query to PostgreSQL issued from within PHP3.
>
> I connect with no problems to the database, and I can even get the number of
> elements returned by my query like below:
>
>    $result = pg_exec( $pgconn, "select ... from ... where ..." ) or
> die("Query formatted wrong!");
>    $elements = pg_numrows( $result );
>
> But when I try to access some columns inside each row returned, as with the
> lines below
>
> line 59     $i=0;
> line 60     $temp = pg_result($result, $i, "htl.nom_htl");
>
> I get the following error:
>
>   Warning: Bad column offset specified in
> /usr/local/etc/httpd/htdocs/myscript.php3 on line 60

The problem is probably with your column labels in the select statement, which you have not provided in your original
message.In this case "htl.nom_htl" should be listed in the select statement. Also notice that although PostgreSQL is
caseinsensitive, the PHP function "pg_result" is not. So, if 
you have a query like

   $result = pg_exec( $pgconn, "select Test from ..." )

you will have the same

  Warning: Bad column offset ...

if you try

   $temp = pg_result($result, $i, "Test");

The correct answer may be obtained with the lowercase column label

   $temp = pg_result($result, $i, "test");

> I tried to make '$i=1' initially, but then I get the following error:
>
> Warning: Unable to jump to row 1 on PostgresSQL result index 3 in
>  /usr/local/etc/httpd/htdocs/myscript.php3 on line 60

This happens because your query results in only one row, associated to the index $i  = 0!

Hope this may help you solve your problem.

--
Mauricio C. de Oliveira
mailto:carvalho@dt.fee.unicamp.br
http://www.dt.fee.unicamp.br/~carvalho




pgsql-general by date:

Previous
From: Robert Williams
Date:
Subject: auto increment?
Next
From: "David Hartwig"
Date:
Subject: Re: [GENERAL] auto increment?