Just installed/tested MySQL - works great. Now working the DBI to manipulate a db. I want to get a count of rows in a table.
In MySQL, it's:
SELECT COUNT(*) FROM MYTABLE;
In DBI I've tried several different things with no success. The FAQ appears to be down. My books Programming the Perl DBI and MySQL and msql appear to have great examples for advanced concepts, but not for the most primitive examples like this one. The online DBI docs state (under the section for the rows method):
One alternative method to get a row count for a SELECT is to execute a ``SELECT COUNT(*) FROM ...'' SQL statement with the same ``...'' as your query and then fetch the row count from that.
But I guess I just haven't had enough coffee. My snippet:
my $sth = $dbh->prepare( "SELECT COUNT(*) FROM " . $tablename );
my $rowscount = $sth->rows;
There are 2 recs in the table, but $rowscount contains 1.
Would appreciate a clue, TIA,