note 27117 added to function.odbc-num-rows
| From: | webmaster at walia dot com | Date: | Sat, 23 Nov 2002 13:09:59 +0000 |
| Subject: | note 27117 added to function.odbc-num-rows | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39894@lists.php.net to get a copy of this message | ||
if you are using ODBC you will get -1 as the answer to this command most of the time. I tried this
on windows (sigh) and it did not work.
If you are using ODBC with a DSN for MS ACCESS then the best method would be
CODE:
--------
$connection = odbc_connect("DSN_name","userid","password") or
die("ERROR");
$sql = "SELECT COUNT(*) FROM tablename";
$sql_result = odbc_prepare($connection,$sql) or die("ERROR");
odbc_execute($sql_result) or die("ERROR");
$rc = odbc_fetch_into($sql_result, $my_array);
echo ("Total rows: " . $my_array[0]);
odbc_free_result($sql_result);
odbc_close($connection);
--------
This way you do not have to go through loops and stuff. imagine if you had over 100,000 entried
(rows) and you tried to count them using a loop with incrememnting counter. It would really screw up
the CPU. specially if you get 100 people doing the same thing at the same time (which you never
know)
Using this method is fast and most convenient for me at least.
--
http://www.php.net/manual/en/function.odbc-num-rows.php
http://master.php.net/manage/user-notes.php?action=edit+27117
http://master.php.net/manage/user-notes.php?action=delete+27117
http://master.php.net/manage/user-notes.php?action=reject+27117