Using DBI for mysql, I have a list of tables to query. Problem is, the list is supplied by someone else and may contain errors, meaning it may direct the script to query a table that does not exist. If this happens, it's important that the script not terminate in an error. Here's the typical code:
So, I was thinking of two possibilities:for $i (0 ..$#tables_to_query) { $sql = "select count(*) from ".$tables_to_query[$i].";"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->er +rstr); $sth->execute() or die("Could not execute!" . $dbh->errstr); $total = $sth->fetchrow_array(); print "Total $i is $total\n"; }
SELECT count(*) FROM r6019 WHERE EXISTS (SELECT * FROM r6019);
http://dev.mysql.com/doc/mysql/en/exists-and-not-exists-subqueries.html
but it produces an sql error.
What I don't want to do is use a SHOW TABLES and iterate through the results, because there are tens of thousands of tables in the database. I'm looking for something clean and simple.
Thanks
Forget that fear of gravity,
Get a little savagery in your life.
In reply to Best Perlish way to test if a mysql table exists? by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |