Re: PHP and PostgreSQL

From: Partyka Robert <bobson(at)saturn(dot)alpha(dot)pl>
To: Uro Gruber <uros(at)sir-mag(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PHP and PostgreSQL
Date: 2001-01-06 09:14:37
Message-ID: Pine.LNX.4.21.0101060959240.20282-100000@saturn.alpha.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-php

Hi

I think You misunderstand the function You use. What was You expect to get
when You try to access to not exsisting row? When You are doing "while" it
will exit on ``false'' value - so when You access to not existing row the
function produce ``false'', but also PHP produce Error message if You dont
prevent it in php.ini or with "@" before function call. See that Yours
code will exit "while" loop when You $row counter will get 4. First $row
is set to 4 then "while" test the return value of function in $data. So
don't be suprised such error warning. You are try to gen not existing
object.

If mysql relevant function dont produce error warning in such situation
IMHO is something wrong with mysql access function in PHP rather than
postgreSQL access function. But ... let's don't start wars again ;)

BTW... IMHO it is not good practice to use errors as exit code for
loops. Feel free to disagree ;))))

regards
Robert

> Hi!
>
> I have some questions about coding in php with postgre.
>
> Here is my code
>
> $qu = pg_exec ($db_conn, "SELECT * FROM clients ORDER BY username");
> $row = 0; // postgres needs a row counter other dbs might not
> while ($data = @pg_fetch_object ($qu, $row)) {
> echo $data->username." (";
> echo $data->password ."): ";
> echo $data->client_id."<BR>";
> $row++;
> }
>
> When i execute this i get 3 records (in DB is also 3 records), if i
> delete @ before pg_fetch_object i get an error:
>
> "Unable to jump to row 3 on PostgreSQL result index 4"
>
> I understand what's wrong and i know why is that @.
>
> What i do want to know is, if there is something wrong with this
> function or am i doing something wrong. I don't like that kind of
> errors. How can i stop before the end.
>
> In mysql there was no need to count rows.
>
> Thanks
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Denis Perchine 2001-01-06 09:38:19 Problems with order by, limit, and indices
Previous Message Adam Haberlach 2001-01-06 06:07:28 Re: PHP and PostgreSQL

Browse pgsql-php by date

  From Date Subject
Next Message Frank Joerdens 2001-01-06 16:12:27 Re: PHP and PostgreSQL
Previous Message Adam Haberlach 2001-01-06 06:07:28 Re: PHP and PostgreSQL