[unixODBC-support] differences between php_odbc_nun_rows and isql command output

Brian Morton bmorton at secureworks.com
Mon Dec 12 14:45:59 GMT 2005


>From the php site:

 paul at mNoOvSePtAoMiNcOeSlPaMnNdO dot ScPoAmM
30-Sep-2004 02:25
Here's a quick and dirty function that *should* return the number of rows in
a query even if the driver is being ornery.

<?php
function better_odbc_num_rows($con,$sql){
   $result = odbc_exec($con,$sql);
   $count=0;
   while($temp = odbc_fetch_into($result, &$counter)){
       $count++;
   }
   return $count;
}
?>

$con is your ODBC connection, and $sql is your SQL query. Put it in your
header and you should be good to go.

You also have the option of doing count(*) as num_rows as a select field in
your query.  That field num_rows will contain a count of the number of rows
selected during the query.

-----Original Message-----
From: Roger "Peña" Escobio [mailto:orkcu at yahoo.com] 
Sent: Monday, December 12, 2005 9:28 AM
To: Support for the unixODBC project
Subject: [unixODBC-support] differences between php_odbc_nun_rows and isql
command output

Hi
please appologies for asking php stuff in this list, but I coundn't find any
other place where to ask about odbc specific problems with php

I am having problems with the odbc_nun_rows() php function to get the number
of rows I get from a query, it always return -1 (from the php site it looks
that it is a very common problem) but when I run the same query with isql
command I get the right results.....

my next stept was to find any difference in the way each client ask for the
num_rows, but both use the same SQL function: SQLRowCount() prety much in
the same way :-( I get stuck so anybody here know the reason of this
behaivor or just may help me to continue the research to find and fix this
bug ?

both clients: php and isql, use the same enviroment:
unixODBC and freeTDS packages, MSSQL-2k server [roger at sauron ~]$ rpm -q
unixODBC
unixODBC-2.2.9-1
[roger at sauron ~]$ rpm -q freetds
freetds-0.63-1.2.el4.rf
[roger at sauron ~]$

and CentOS-4.2+updates linux distribution addicional information: I compiled
the most recent
php4 (4.4.1) with no diffence with the one supply by the distribution

thanks in advance for any tip

roger

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com _______________________________________________
unixODBC-support mailing list
unixODBC-support at easysoft.com
http://mail.easysoft.com/mailman/listinfo/unixodbc-support




More information about the unixODBC-support mailing list