[CentOS] about php-ODBC , unixODBC, freetds and MSSQL server

Mon Dec 5 01:50:23 UTC 2005
Roger Peña Escobio <orkcu at yahoo.com>

maybe someone here can help me understand why I am
getting this strange behaivor.

I am connecting to a MS SQL server from PHP by the
ODBC module, I use unixODBC-2.2.9-1,
freetds-0.63-1.2.el4.rf and php-4.3.9-3.9 all but the
freetds package came with CentOS-4.2 + updates

the problem is that I am getting -1 from the
odbc_num_rows(); function, I search the net and it
looks that this is a very common problem with MS SQL
server and unix ODBC driver, but, my surprise came
when I use the isql command (came with the unixODBC
package) and the number of rows is returned
correctly in the same machine and with the same query.
the following is the output from isql command:

+--------------+-----------+---------------------------------------+
SQLRowCount returns 2516
2516 rows fetched
SQL>

then I look forward in the source files and I found
that both clients (php module and isql) use the same
function to get the number of rows:

from isql.c :

static void
WriteFooterNormal( SQLHSTMT hStmt, SQLCHAR
*szSepLine,
SQLLEN nRows )
{
    SQLLEN  nRowsAffected	= -1;

	printf( (char*)szSepLine );

    SQLRowCount( hStmt, &nRowsAffected );
    printf( "SQLRowCount returns %d\n", nRowsAffected
);

    if ( nRows )
    {
    	printf( "%d rows fetched\n", nRows );
    }
}



from odbc php module php_odbc.c :

/* {{{ proto int odbc_num_rows(resource result_id)
   Get number of rows in a result */
PHP_FUNCTION(odbc_num_rows)
{
	odbc_result *result;
	SDWORD rows;
	pval **pv_res;
	
	if (zend_get_parameters_ex(1, &pv_res) == FAILURE)
{
		WRONG_PARAM_COUNT;
	}
	ZEND_FETCH_RESOURCE(result, odbc_result *, pv_res,
-1, "ODBC result", le_result);
	SQLRowCount(result->stmt, &rows);
	RETURN_LONG(rows);
}
/* }}} */

so I get confuse, why an odbc client get the right
result and the other don't if both use the same
query, same odbc configuration, same libraries files,
same
driver (freetds)

I am a complete newbie with odbc, MS SQL and freetds
:-(
and with very litle knowledge of php modules

can anybody help me ?

thanks in advance
roger



		
__________________________________________ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com