Re: Bug #1611: odbc_num_rows() can't get rows num

From: Date: Mon, 28 Jun 1999 23:57:41 +0000
Subject: Re: Bug #1611: odbc_num_rows() can't get rows num
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-7772@lists.php.net to get a copy of this message
> From: wjw@hongzhi.com > Operating system: winNT > PHP version: 3.0.11 > PHP Bug Type: ODBC related > Bug description: odbc_num_rows() can't get rows num > > > i use odbc_num_rows() can't get rows num only get -1 > follow the code i use odbc get dbase & SQL dbase can't get num rows For odbc_num_rows() to work, I'm thinking that the underlying ODBC driver might need to implement bookmarks (at least, that's how MS ADO does it). If it just calls SQLRowCount() and if you performed a SELECT query, then the behavior is driver-defined, though it is usually the number of rows in the recordset. Here's what the Microsoft ODBC 2.0 reference says about SQLRowCount(): "For UPDATE, INSERT, and DELETE statements and for the SQL_UPDATE, SQL_ADD, and SQL_DELETE operations in SQLSetPos, pcrow is the number of rows affected by the request or -1 if the number of affected rows is not available. For other statements and functions, the driver may define the value of pcrow. For example, some data sources may be able to return the number of rows returned by a SELECT statement or a catalog function before fetching the rows. Note Many data sources cannot return the number of rows in a result set before fetching them; for maximum interoperability, applications should not rely on this behavior." My driver, DirList2ODBC, never returns -1, but some drivers such as dBase might return -1 due to either laziness ;-) or lack of support in the underlying DBMS. Check how you open the recordset. If you are opening with a forward-only cursor, you cannot get the record count in many situations. Be sure to open the cursor as either dynamic, keyset-based, or static, depending on your cup of tea. (I didn't have a chance to look at your source code yet :-(. Good luck :-) --Steven Lawrance-- Personal Web Site and E-Mail: slawrance@technologist.com http://www.bryant.edu/~ssl2 (SSL2)

« previous php.dev (#7772) next »