Received: from newsnipple.com (www.newsnipple.com [208.243.144.102]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f06628767813 for ; Sat, 6 Jan 2001 01:02:09 -0500 (EST) (envelope-from adam@newsnipple.com) Received: by newsnipple.com (Postfix, from userid 1000) id 785683116E; Fri, 5 Jan 2001 22:07:28 -0800 (PST) Date: Fri, 5 Jan 2001 22:07:28 -0800 From: Adam Haberlach To: Uro Gruber Cc: pgsql-general@postgresql.org Subject: Re: PHP and PostgreSQL Message-ID: <20010105220727.B4224@newsnipple.com> References: <631076786.20010105231729@sir-mag.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <631076786.20010105231729@sir-mag.com>; from uros@sir-mag.com on Fri, Jan 05, 2001 at 11:17:29PM +0100 X-Archive-Number: 200101/218 X-Sequence-Number: 2387 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."
"; > $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. for($i=0; $i < pg_numrows($qu); $i++) { $data = pg_fetch_object($qu, $row); echo $data->username." ("; echo $data->password ." )"; echo $data->client_id."
>"; } You can blame the PHP people for having wildly dissimilar systems for iterating through result sets... > In mysql there was no need to count rows. Let's not start the MySQL vs. Postgres wars again... :) -- Adam Haberlach |A cat spends her life conflicted between a adam@newsnipple.com |deep, passionate, and profound desire for http://www.newsnipple.com |fish and an equally deep, passionate, and '88 EX500 |profound desire to avoid getting wet.