Skip site navigation (1) Skip section navigation (2)

[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 (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novicepgsql-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

pgsql-novice by date

Next:From: brewDate: 2001-11-15 23:09:39
Subject: Re: Perl and pgsql...
Previous:From: Poul KristensenDate: 2001-11-15 21:58:54
Subject: java and postgres

pgsql-php by date

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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group