## Code is to be considered untested. ## This assumes that each *$i* has only one table name and no other characters in it $mysql_table_path = "Your path to your databases"; $dbname="The name of the database"; $db_extension="The file extension for your database type"; for $i (0 ..$#tables_to_query) { $filepath = "$mysql_table_path/$dbname/" . $tables_to_query[$i] .".$db_extension"; if (-e $filepath) { $sql = "select count(*) from ".$tables_to_query[$i].";"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr); $sth->execute() or die("Could not execute!" . $dbh->errstr); $total = $sth->fetchrow_array(); print "Total $i is $total\n"; } }