Re: return # of rows
| From: | Manuel Lemos | Date: | Mon, 03 Jul 2000 05:52:32 +0000 |
| Subject: | Re: return # of rows | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-821@lists.php.net to get a copy of this message | ||
Hello Steven,
On 03-Jul-00 00:42:02, you wrote:
>> >echo odbc_num_rows($result);
>>
>> >^^^^^^ is returning a -1 ????
>>
>> >Iam running php 4.0 with MS SQL 7 on NT 4 IIS4.
>>
>> There is no way to know how many rows a query returns with high end
>> databases like MS-SQL, Oracle, etc. because these database return rows
>> asyncrounously, ie, they start returning result rows to the client
>> even before the query search has ended on the server. So, when you call
>> the function to get you the number of rows it can't tell you because the
>> query search might not have finished on the server.
>Why not do a $query = "SELECT COUNT(ROWNAME) FROM TABLENAME";
>?
Sure, that's the recommended way if can be sure that there is no chance
that that the count of rows will not change between the two selects. Keep
in mind that databases may be accessed by multiple users that may cause it
to be changed and the query results may noy be consistent if you don't take the
necessary precautions.
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.
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
--