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
kevin7
Forum Commoner
Posts: 96 Joined: Fri May 21, 2004 6:54 am
Post
by kevin7 » Mon May 24, 2004 11:51 pm
how we know a table is existed in a database?
i want to make a table that is randomly generated using php...
tq
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 25, 2004 12:03 am
"CREATE TABLE `$randomName`"
fails a query.
kevin7
Forum Commoner
Posts: 96 Joined: Fri May 21, 2004 6:54 am
Post
by kevin7 » Tue May 25, 2004 12:43 am
hmm... u means if a error message come out... means.. the table is exist?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 25, 2004 12:44 am
yep
kevin7
Forum Commoner
Posts: 96 Joined: Fri May 21, 2004 6:54 am
Post
by kevin7 » Tue May 25, 2004 12:53 am
how can i capture the error message?
i'm a newbie...
tq
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 25, 2004 12:56 am
Code: Select all
$check = mysql_query("CREATE TABLE `$randomName`") or -1;
if($check === -1)
{// it existed
}
else
{// it was created
}
mendingo
Forum Commoner
Posts: 28 Joined: Sun May 23, 2004 1:27 pm
Post
by mendingo » Tue May 25, 2004 2:42 am
Won't that leave you with an unwanted table in MYSQL if the table didn't exist?
Surely a better way is to run a SELECT statement on it and see if it fails:
Code: Select all
$results = mysql_query("SELECT * FROM table");
if($results)
{
//table exists
}
else
{
//table doesn't exist
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 25, 2004 2:44 am
read the post:
kevin7 wrote: i want to make a table that is randomly generated using php...