in reply to DBI: Better way to find number of rows in a table?

If your DBI and the MySQL bits are recent, you can do this:

# $dbi handle is available my @non_empties = grep { # almost like jeffa's now $dbh->selectcol_arrayref("select count(*) from $_")->[0] } $dbh->tables;

Update: rnahi is correct, $sth->rows won't do. Repaired

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: DBI: Better way to find number of rows in a table?
by rnahi (Curate) on Jun 04, 2003 at 08:29 UTC

    This won't work as expected.

    $sth->rows returns the number of affected rows, and since in this case there are none, (COUNT is not a row affecting command) it will return -1, thus making TRUE all the items in the array. Therefore grep will return all the tables, even the empty ones.