... or :
CREATE TABLE IF NOT EXISTS mytable (...)
Main Topics
Browse All TopicsI need a way to determin if a table exists in a MySQL database prior to creating it.
This function needs to work in PHP
Ex
if (!tablename exists)
{
CREATE TABLE tablename (field 1, etc....)
}
else
{
echo "Table existss already!"
}
I need the function that determines if the tablename exists.
Thanks,
Keith
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
... or :
USE thedatabase;
SHOW TABLES
<here parse the results searching for that table>
all the source is in the gestDB.php.txt sample source I give for free on www.edainworks.com category "3rd party tools", "development"
Business Accounts
Answer for Membership
by: SqueebeePosted on 2003-10-06 at 14:53:53ID: 9501494
You could always catch the error when the table does exist:
i.e.:
mysql> create table item(myrow INT);
ERROR 1050: Table 'item' already exists
Use the mysql_errno() function in PHP after calling the create table and if you get error 1050 tell the user the table already existed. In this situation I would do an error catch so as to not slow your code down with checks for existing tables that may not necesscarily need to be done.
That being said, you could parse the output of SHOW TABLES to see if the tablename is amoung the tables listed.