From: Gavin M. Roy <gmr@ehpg.net>
To: Mihail Mihailov <Mihail.Mihailov@uta.fi>
Cc: pgsql-php@postgresql.org
Subject: Re: Retrieving result of COUNT(*) with PHP
Date: Wed, 28 Mar 2007 14:18:34 -0700
Message-ID: <5b599cc10703281418j65c65ce7g537c7cc7fb32cbc5@mail.gmail.com> (raw)
In-Reply-To: <20070329000511.qidyijwozuo0w0w4@imp3.uta.fi>
References: <C2303737.4AFAD%lynna@spidersilk.net>
<20070329000511.qidyijwozuo0w0w4@imp3.uta.fi>
On 3/28/07, Mihail Mihailov <Mihail.Mihailov@uta.fi> wrote:
>
>
> Another way to calculate number of rows in the result is to use
> pg_num_rows function.
> $res = pg_query("SELECT COUNT(*) AS result_count FROM etc. WHERE etc.");
> $count = pg_num_rows($res);
I dont think this will work as expected. PostgreSQL will return 1 row and
your $count var will be 1. If you do SELECT * FROM it would return the
proper result. Not very effective for speed though.
http://www.varlena.com/GeneralBits/120.php has some good suggestions for
dealing with count(*) speed issues.
Gavin
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: gmr@ehpg.net, Mihail.Mihailov@uta.fi
Subject: Re: Retrieving result of COUNT(*) with PHP
In-Reply-To: <5b599cc10703281418j65c65ce7g537c7cc7fb32cbc5@mail.gmail.com>
References: <C2303737.4AFAD%lynna@spidersilk.net> <20070329000511.qidyijwozuo0w0w4@imp3.uta.fi> <5b599cc10703281418j65c65ce7g537c7cc7fb32cbc5@mail.gmail.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