pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adam Haberlach <adam@newsnipple.com>
To: GH <grasshacker@over-yonder.net>
Cc: Adam Haberlach <adam@newsnipple.com>
Cc: Uro Gruber <uros@sir-mag.com>
Cc: pgsql-general@postgresql.org
Subject: Re: PHP and PostgreSQL
Date: Sun, 7 Jan 2001 19:40:01 -0800
Message-ID: <20010107194001.B16787@newsnipple.com> (raw)
In-Reply-To: <20010106115251.B59573@over-yonder.net>
References: <631076786.20010105231729@sir-mag.com>
	<20010105220727.B4224@newsnipple.com>
	<20010106112207.A59573@over-yonder.net>
	<20010106115251.B59573@over-yonder.net>

On Sat, Jan 06, 2001 at 11:52:51AM -0600, GH wrote:
> On Sat, Jan 06, 2001 at 11:22:07AM -0600, some SMTP stream spewed forth: 
> > On Fri, Jan 05, 2001 at 10:07:28PM -0800, some SMTP stream spewed forth: 
> > > 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.
> > > 
> > $nr=pg_numrows($qu);
> > for($i=0; $i < $nr; $i++)
> > 
> (And I wasn't even drunk at type-time.)
>        (adds)
> > This add another variable in exchange for saving an obscene amount of 
> > time counting rows on every iteration.
> > 

	I've always assumed that the number of rows is known by the result set
so pg_numrows() is merely a (arguably) trivial lookup.  Now that I've
looked at the code, that assumption looks correct.  The overhead seems
to be one PHP function call and two C function calls.  No counting,
no loops, no obscenities.  Unless PQntuples() is really stupid, but
I'm not going to wander through another source tree tonight.

-- 
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.



view thread (10+ messages)  latest in thread

Message-ID: <20010107194001.B16787@newsnipple.com>
Permalink:  ../20010107194001.B16787@newsnipple.com/
Also on:    postgresql.org/message-id/20010107194001.B16787@newsnipple.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: adam@newsnipple.com, grasshacker@over-yonder.net, uros@sir-mag.com, pgsql-general@postgresql.org
  Subject: Re: PHP and PostgreSQL
  In-Reply-To: <20010107194001.B16787@newsnipple.com>
  References: <631076786.20010105231729@sir-mag.com> <20010105220727.B4224@newsnipple.com> <20010106112207.A59573@over-yonder.net> <20010106115251.B59573@over-yonder.net> <20010107194001.B16787@newsnipple.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox