I know this could be done, but I do not know if it is the best way. All of the mysql tables are stored in a directory as tablen_name.file_extension. I am not sure if the file extension is the same for every table type or not (mine are *.ISDm, *.ISM and *.frm). Something liek this (minimally tested)
## Code is to be considered untested.
## This assumes that each *$i* has only one table name and no other ch
+aracters 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";
}
}
You can find the path to the db directory in the configuration file, either "/etc/mysql/my.cnf" or "/etc/my.cnf". If might be somewhere else, but I have always found it in one of these places. The line you want is the "datadir=" line. If all of your tables are the same database type, then they should all have the same extensions (as far as I know).
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysql.server]
user=mysql
basedir=/var/lib
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
It works for me on my system, but I do not have the number of tables that you have, and probably not the same setup. This is obviously black magic, as I know of no guarentee that the tables will always be exposed like this, but it it does work for me.
Otherwise, your best bet (and the best solution) sounds like you need to trap the errors.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.