Re: [GENERAL] Re: Bad column offset?

From: "Paulo Parola" <pparola(at)brazilinfo(dot)com>
To: "pgsql-general" <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Re: Bad column offset?
Date: 1999-01-25 13:41:46
Message-ID: 004801be4868$79263ba0$0300000a@cpqivx-2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>
>> 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 case insensitive, 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");

Check out the following test example I have made which gives me the same
error. Note that the name of the table is 'htl' in lowercase and the
selected field is 'nom_htl', also lowercase. So there is no type mismatch in
terms of lowercase/uppercase. Note also that elements are indeed returned
from this query.

---------------------------------------------
<?
if ( !($pgconn = pg_connect("localhost", "5432", "", "", "testdb")) )
{
echo "Bad connection to database!<p>Sorry<p>.\n";
}
else
{
echo "<body>\nConnection OK.<br><br>\n";
$result = pg_exec( $pgconn, "select htl.nom_htl from htl where
htl.des_det_htl='s'" ) or die("Query formatted wrong!");

$number_of_records = pg_numrows( $result );

echo "Number of elements returned: $number_of_records<br>";

if ($number_of_records==0)
echo "<p>No records matching your criteria were found. ";

if ($number_of_records!=0) {
$i=0;
$temp = pg_result($result, $i, "htl.nom_htl");
echo "<br>Field 'nom_htl' of first element returned: ";
echo "$temp";
}

if ( !pg_close( $pgconn ) )
echo "<!-- Bad Close.-->\n";
}

echo "<br><br>End of page";
echo "</body>";
?>
---------------------------------------------

The output of this script printed to the screen is the following:

---------------------------------------------
Connection OK.

Number of elements returned: 63

Warning: Bad column offset specified in
/usr/local/etc/httpd/htdocs/myscript.php3 on line 21

Field 'nom_htl' of first element returned:

End of page
---------------------------------------------

Now, any tips on what's going wrong here?

TIA,

Paulo Parola
pparola(at)brazilinfo(dot)com

Browse pgsql-general by date

  From Date Subject
Next Message Johnson Jr., Randall S. 1999-01-25 15:48:46 [GENERAL] PostgreSQL and mod_perl trouble (spinlock)
Previous Message Sebestyen Zoltan 1999-01-25 13:10:36 How to debug a plpgsql script.