Re: return # of rows
| From: | Manuel Lemos | Date: | Tue, 18 Jul 2000 04:12:37 +0000 |
| Subject: | Re: return # of rows | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-1228@lists.php.net to get a copy of this message | ||
Hello Steven,
On 03-Jul-00 12:00:32, you wrote:
>> On a side now, don't forget that count(rowname) may return a different
>> number than count(*) if row name has NULLs on it.
>>
>> >True, PHP doesn't handle the count, MS-SQL does. But it's guaranteed to
>> >be accurate (from whenever you executed the query plus a few
>> >milliseconds of lag time).
>>
>> If nobody else changes the database as noted above.
>>
>> >Then you don't need to worry about broken odbc_num_rows anymore...
>>
>> Notice that odbc_num_rows is not broken. It just returns what the ODBC
>> driver returns.
>Note that under Microsoft SQL, the COUNT aggregate function with a (*)
>argument returns the count of _ALL_ rows, not just NON-NULL values...
What I meant is that COUNT(rowname) does not count the rows where rowname
is NULL, unlike COUNT(*) that counts all.
>The following should do as you ask, as long as you have M$ SQL. It will
>probably also work under variants of Sybase:
Yes, but I think that using transactions to count rows is usually an
overkill. What I meant is that you'd better not rely on the number
returned by a COUNT() value.
For instance, do not use it in loops to determine when a subsequent query
that asks for the row data because somebody may delete rows between the
SELECT COUNT(*) and the SELECT data statements you may end up expecting
more data then what you will get.
It would be harmless to display the count number though, even it it was not
consistent.
Regards,
Manuel Lemos
Web Programming Components using PHP Classes.
Look at: http://phpclasses.UpperDesign.com/?user=mlemos@acm.org
--
E-mail: mlemos@acm.org
URL: http://www.mlemos.e-na.net/
PGP key: http://www.mlemos.e-na.net/ManuelLemos.pgp
--