[PHP] Re: psql with PHP question

From: "Culley Harrelson" <Culley_Harrelson(at)pgn(dot)com>
To: <philip(at)adhesivemedia(dot)com>, <beloshapka(at)mnogo(dot)ru>
Cc: <gee308(at)mediaone(dot)net>, <pgsql-general(at)postgresql(dot)org>, <pgsql-novice(at)postgresql(dot)org>, <pgsql-php(at)postgresql(dot)org>
Subject: [PHP] Re: psql with PHP question
Date: 2001-11-15 22:34:18
Message-ID: sbf3d287.009@pgn.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-novice pgsql-php

Im sure it takes more memory but my preferred method is:

$q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) FROM article)");
$data = pg_fetch_object ($q, 0);
$maxid = $data->id;
echo "The highest id is ". $maxid;

To me this is more self-documenting and easier to maintian...

culley

>>> Philip Hallstrom <philip(at)adhesivemedia(dot)com> 05/03/01 08:29AM >>>
Also... is there any reason you don't just do:

SELECT MAX(id) FROM article

rather than what you have below? It would get you the same thing wouldn't
it and save a query...

On Thu, 3 May 2001, Chris Ryan wrote:

> Jason,
>
> Look into the pg_result() function. You would use it something like
> this:
>
> $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id) FROM
> article)");
> $maxid = pg_result($q,0,0); # pg_result($result,$row,$column_num)
> echo "The highest id is ". $maxid[0];
>
> Hope this helps.
>
> Chris Ryan
> chris(at)greatbridge(dot)com
>
> Jason wrote:
> >
> > Hi, I want to try and optimize my calls to postgreSQL from PHP. If
> > I only need one field from a select statement, what should I use? I am
> > currently using:
> > $q = pg_Exec("SELECT id FROM article WHERE id=(SELECT MAX(id)
> > FROM article)");
> > $maxid = pg_fetch_array($q, 0);
> > echo "The highest id is ". $maxid[0];
> > What can I use besides an array to get a single value? In general, using
> > a single variable always saves more memory than using an array? Thank
> > you.
> > Jason
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/users-lounge/docs/faq.html
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Browse pgsql-general by date

  From Date Subject
Next Message K. Ari Krupnikov 2001-11-15 22:35:32 return an array as aggregate result?
Previous Message Glenn Sullivan 2001-11-15 22:32:14 spectral datasets in postgresql

Browse pgsql-novice by date

  From Date Subject
Next Message brew 2001-11-15 23:09:39 Re: Perl and pgsql...
Previous Message Poul Kristensen 2001-11-15 21:58:54 java and postgres

Browse pgsql-php by date

  From Date Subject
Next Message Tatsuo Ishii 2001-11-16 01:08:18 Re: [HACKERS] [PHP] PostgreSQL / PHP Overrun Error
Previous Message Steve Wolfe 2001-11-15 21:39:50 Re: [PHP] Re: SQL Load Balancer for PostgreSQL