Re: return # of rows

From: Date: Mon, 03 Jul 2000 02:42:02 +0000
Subject: Re: return # of rows
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-816@lists.php.net to get a copy of this message
Manuel Lemos wrote: > > Hello Chuck, > > On 28-Jun-00 16:21:54, 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"; ? 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). Then you just do your typical: $result = odbc_exec($connection, $query); while(odbc_fetch_row($result)) { $numrows = (integer) odbc_result($result, 1); } // end of while row = sybase_fetch_row Check the value of $numrows, and you're away to the races... Then you don't need to worry about broken odbc_num_rows anymore...

« previous php.db (#816) next »