RE: [PHP] Checking whether a MySQL table exists
| From: | Sander Pilon | Date: | Tue, 09 Jan 2001 22:04:16 +0000 |
| Subject: | RE: [PHP] Checking whether a MySQL table exists | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33562@lists.php.net to get a copy of this message | ||
> > Is there a command to check for the existence of a MySQL table?
> >
>
> $res=mysql_query("show tables");
>
> you have to search for the name manually!
> for example:
>
> while ($row=mysql_fetch_array($res)){
> foreach ($row as $key => $value){
> echo "$key -> $value<br>";
> }
> }
>
Does nobody read the mysql manual anymore these days? :)
No manual searching needed -
$r = mysql_query("show tables like '$whateveryouaresearchingfor'");
if( mysql_num_rows($r) == 1 )
{
// found
}
else
{
// not found
}