Checking if table exists

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rockboy
Forum Newbie
Posts: 3
Joined: Mon Jan 09, 2006 7:09 pm
Location: Brisbane, AUSTRALIA

Checking if table exists

Post by rockboy »

hello

i'm trying to write a function which creates tables when they don't already exist, i have seen the mysql_list_tables function and could build something of that but i was wondering if there was already a cleaner way of doing this.

eg:

Code: Select all

if (table_exists("members")){
....
}
thanx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there's two sides: checking, or telling MySQL to create it always (with the constraint that the table must not exist to run it).

for the latter, check the CREATE TABLE documentation.

http://dev.mysql.com/doc/refman/4.1/en/ ... table.html
Post Reply