note 26229 added to function.odbc-num-rows
| From: | fergus at serif dot net | Date: | Wed, 23 Oct 2002 13:21:01 +0000 |
| Subject: | note 26229 added to function.odbc-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-38450@lists.php.net to get a copy of this message | ||
building on masuod_a@hotmail.com's note, above, I made this function which is similar but uses
the SQL count(*) recomended in other notes. I've tested this against masuod_a's function
and this is much faster for me.
function odbc_record_count($result, $conn, $db, $options) {
$numRecords=odbc_num_rows($result);
if ($numRecords<0) {
$countQueryString = "SELECT count(*) FROM $db $options";
$count = odbc_exec($conn, $countQueryString);
$numRecords = odbc_result($count, 1);
}
return $numRecords;
}
called like this: odbc_record_count($result, $conn, $dsn, "myField='myValue'");
where $result is the indicator to try first with odbc_num_rows, $conn is the result of your original
odbc_connect, $dsn is the DSN used to get $conn and also works as the table name for the count(*),
and $options is to add any WHERE this = 'that' SQL arguments.
--
http://www.php.net/manual/en/function.odbc-num-rows.php
http://master.php.net/manage/user-notes.php?action=edit+26229
http://master.php.net/manage/user-notes.php?action=delete+26229
http://master.php.net/manage/user-notes.php?action=reject+26229