note 26229 deleted from function.odbc-num-rows by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 09:04:28 +0000 |
| Subject: | note 26229 deleted from function.odbc-num-rows by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-196884@lists.php.net to get a copy of this message | ||
Note Submitter: fergus at serif dot net
----
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.