Functions to return row count and field count

It’s great to see that people are downloading our the February CTP build of our PHP driver and that we’re getting feedback on our new features. We look forward to more of your feedback and we’re in the process of setting up a new forum specifically for questions and feedback for the PHP driver.

A lot of the feedback has centered around requests for a num_rows function for the PHP driver. In our PHP driver, we’re using the most performant way to retrieve the results of a SQL Server query, a forward-only read-only stream of data. With this approach there’s no way for the driver to know how the total number of rows that the query will return until you’ve finished processing the results of the query. We could offer a num_rows function but without providing buffered resultsets, that num_rows function would only return the number of rows returned so far. While that appears to be a fairly standard behavior for drivers that don’t support buffered resultsets, it doesn’t strike me as adding a great deal of value. With that said, I’m curious as to whether there’s real interest in a num_rows function without adding support for buffered resultsets?

We are planning on adding a function to return the number of fields in a resultset later in this release. There’s a simple workaround in the meantime – use the count function in conjunction with sqlsrv_field_metadata:

$fieldCount = count(sqlsrv_field_metadata($stmt));

The main benefit in adding a function to return this information is that returning the number of fields without generating the field metadata would be more performant.

David Sceppa

Program Manager, SQL Server Driver for PHP