note 64007 added to function.odbc-fetch-row
| From: | michael dot buergi at gmx dot net | Date: | Wed, 05 Apr 2006 12:11:28 +0000 |
| Subject: | note 64007 added to function.odbc-fetch-row | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107378@lists.php.net to get a copy of this message | ||
Thanks for the binary search code, romanziak. However, it does not work correct in all cases. I
corrected your version and added some code to complete the custom num_rows() function:
<?php
// note: there should be no calls to odbc_fetch_* after odbc_exec* and
// prior to a call to this function. it would affect the results.
//
// for this reason, you should cache the output of odbc_num_rows()
// and of this function.
//
// original code was tested with php 5.1.2 on iis and mssql server 8.0
//
function num_rows(&$rid) {
// try to use odbc_num_rows
$num= odbc_num_rows($rid);
if ($num >= 0) {
return $num;
}
// optimisation for frequent cases
if (!@odbc_fetch_row($rid, 1)) {
@odbc_fetch_row($rid, 0); // reset cursor
return 0;
}
if (!@odbc_fetch_row($rid, 2)) {
@odbc_fetch_row($rid, 0); // reset cursor
return 1;
}
// use binary search for counting rows for the driver
// won't give us this info...
$lo= 2;
$hi= 8192000; // max number of rows that can be in the result + 1
while ($lo < ($hi - 1)) {
$mid= (int)(($hi + $lo) / 2);
if (@odbc_fetch_row($rid, $mid)) {
$lo= $mid;
} else {
$hi= $mid;
}
}
$num= $lo;
@odbc_fetch_row($rid, 0); // reset cursor
return $num;
}
?>
----
Server IP: 194.153.94.11
Probable Submitter: 80.219.223.191
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.odbc-fetch-row.php
Edit -- http://master.php.net/note/edit/64007
Del: integrated -- http://master.php.net/note/delete/64007/integrated
Del: useless -- http://master.php.net/note/delete/64007/useless
Del: bad code -- http://master.php.net/note/delete/64007/bad+code
Del: spam -- http://master.php.net/note/delete/64007/spam
Del: non-english -- http://master.php.net/note/delete/64007/non-english
Del: in docs -- http://master.php.net/note/delete/64007/in+docs
Del: other reasons-- http://master.php.net/note/delete/64007
Reject -- http://master.php.net/note/reject/64007
Search -- http://master.php.net/manage/user-notes.php