List:General Discussion« Previous MessageNext Message »
From:Roger Baklund Date:September 19 2003 6:12pm
Subject:Re: Is there a way to find out if a table exists?
View as plain text  
* Dan Anderson
> I am trying to make my PHP script autodetect when a table in a mySQL
> database exists, and when it doesn't, create it.
>
> Is there some way to do something like:
>
> SELECT * FROM tables WHERE name = "table_name";
>
> And get a result I could test for truth, and thus run my script?

SHOW TABLES LIKE "table\_name";

Note that the underscore must be escaped with a backslash, because the LIKE
operator use underscore as a wildcard for a single character. In other
words, this statement:

SHOW TABLES LIKE "table_name";

... would match "table_name", but also "tableAname" and tableBname".

--
Roger

Thread
Is there a way to find out if a table exists?Dan Anderson19 Sep
  • Re: Is there a way to find out if a table exists?Roger Baklund19 Sep
  • RE: Is there a way to find out if a table exists?Jennifer Goodie19 Sep
  • Re: Is there a way to find out if a table exists?Don Read19 Sep
    • Re: Is there a way to find out if a table exists?Don Read19 Sep
      • Re: Is there a way to find out if a table exists?Paul DuBois19 Sep