At 12:13 -0400 4/30/02, Andrew Kuebler wrote:
>Everyone on this list has been very helpful so far. I greatly appreciate
>all the help!
>
>I use Perl/DBI with MySQL. Normally to count records, I pull a query
>like:
>
>$a = $db->prepare("SELECT * FROM table");
>$a->execute;
>
>Then:
>
>$numrows = $a->rows;

Yikes!

That's a bad idea for two reasons:
- It pulls the entire table over the network
- The rows() method for SELECT queries is deprecated in the DBI documentation

my $count = $db->selectrow_array ("SELECT COUNT(*) FROM tbl_name");

will give you what you want much more efficiently.

>
>to get a total count of records in the table. Is there an easier/faster
>way to do this if I'm looking only for the total record count for an
>entire table? On a large table, the operations above can be very time
>consuming & processor intensive. I know in the MySQL admin screen you
>can get the total # of items in a table as long as you have at least one
>column indexed & I would assume there is a way to extract that # from
>within Perl. Can anyone help?
>
>Thank you again!
>
>Andrew


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to