Re: checking for tables
| From: | Jay Greenspan | Date: | Sun, 10 Dec 2000 16:15:29 +0000 |
| Subject: | Re: checking for tables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29562@lists.php.net to get a copy of this message | ||
You could also use the mysql SHOW TABLES command.
something like....
mysql_connect("localhost", "username", "password");
mysql_select_db("dbname");
function is_table($desired_table_name)
{
$table_exists = FALSE;
$result = mysql_query("show tables") or die(mysql_error());
while(list($table_name) = mysql_fetch_array($result))
{
if($table_name == $desired_table_name)
{
$table_exists = TRUE;
}
}
return $table_exists;
}
if(is_table("mytable"))
{
echo "yup";
}
?>
on 12/10/00 3:47 AM, Kyle Jerviss at kjj@jerviss.org wrote:
> Here's a little script I wrote to inspect a database:
>
> http://www.jerviss.org/utils/mysql_interrogate_db.phps
>
> The functioning version is at:
>
> http://www.jerviss.org/utils/mysql_interrogate_db.php
>
> you can log in to "localhost" as "www" with no password if you'd like
> to
> see it working. You should be able to see from the source how to get a
> list of tables in a database.
>
> Joe Stump wrote:
>>
>> Anyone know how to check if a MySQL table exists easily?
>>
>> --Joe
>>
>> ---
>> Joe Stump
>> PHP Programmer
>> www.Care2.com
>>