From: | gravity(at)node10065(dot)a2000(dot)nl |
---|---|
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 01:15:28 |
Message-ID: | 20010106021528.C24049@node10065.a2000.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-php |
On Fri, Jan 05, 2001 at 11:17:29PM +0100, Uro Gruber wrote:
> 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.
there are nicer ways (look for one in the db-abstraction layer in PHP-LIB)
but this works:
> $qu = pg_exec ($db_conn, "SELECT * FROM clients ORDER BY username");
$number_of_rows = pg_numrows($qu);
for ($counter=0;$counter<$number_of_rows;$counter++) {
$data_array = pg_fetch_array($qu, $counter);
echo "$data_array[username]";
}
z.
From | Date | Subject | |
---|---|---|---|
Next Message | Alex Pilosov | 2001-01-06 01:38:30 | Re: SHM ids (was running pgsql 7 under Jail'ed virtual machine on FreeBSD 4.2) |
Previous Message | Alfonso Peniche | 2001-01-06 00:18:48 | ODBC 7.x for windows |
From | Date | Subject | |
---|---|---|---|
Next Message | Adam Haberlach | 2001-01-06 06:07:28 | Re: PHP and PostgreSQL |
Previous Message | Uro Gruber | 2001-01-05 22:17:29 | PHP and PostgreSQL |