Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mysql table exists?

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
BE
Hi,

I'm making a online app in which I need to make a mysql-table if it doesn"t already exists? Making the table isn't the problem, but what's the best way to check If a certain table already exists? Is there a function for this?

Or should I load all the tablenames in an array and then check the array for the table I want?

Thanx in advance !!
math
 
perhaps you can check it with
select * from tablename

and see if it returns an error.

you can also drop the table before creating the new one.
drop tablename
create tablename


and the tablenames should be in some kind of systemtables, I guess, but I'm not quite familiar with it yet so perhaps someone else knows
 
<?php
mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;) or
die(&quot;could not connect&quot;);
mysql_select_db(&quot;mydb&quot;);

$result = mysql_list_tables();

while (($row = mysql_fetch_row($result))
printf (&quot;Table: %s\n&quot;, $row[0]);

mysql_free_result($result);
?>
***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top