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

Re: Retrieving result of COUNT(*) with PHP

From: "Gavin M(dot) Roy" <gmr(at)ehpg(dot)net>
To: "Mihail Mihailov" <Mihail(dot)Mihailov(at)uta(dot)fi>
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: Retrieving result of COUNT(*) with PHP
Date: 2007-03-28 21:18:34
Message-ID: 5b599cc10703281418j65c65ce7g537c7cc7fb32cbc5@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-php
On 3/28/07, Mihail Mihailov <Mihail(dot)Mihailov(at)uta(dot)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

In response to

pgsql-php by date

Next:From: Andy ShellamDate: 2007-03-28 21:19:25
Subject: Re: Retrieving result of COUNT(*) with PHP
Previous:From: Mihail MihailovDate: 2007-03-28 21:05:11
Subject: Re: Retrieving result of COUNT(*) with PHP

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