Re: Checking if a table exist



On Thu, 27 Apr 2006 17:17:26 -0700, Jonathan Leffler wrote:

Hi Jonathan

my $sth = $dbh->prepare("SELECT * FROM $tablename");
if ($sth) { ...table exists...probably; you might need to do $sth-
execute to be sure as different DBMS differ... }
else { ...table probably doesn't exist, or it exists but you
don't have select permission on it... }

I'd suggest "Select * from $tablename where 1=2" so that if you do need to call
execute, you return nothing, if at all possible.

--
Ron Savage
ron@xxxxxxxxxxxxx
http://savage.net.au/index.html


.