Page 1 of 1
how to check if a table is existed?
Posted: Mon May 24, 2004 11:51 pm
by kevin7
how we know a table is existed in a database?
i want to make a table that is randomly generated using php...
tq
Posted: Tue May 25, 2004 12:03 am
by feyd
"CREATE TABLE `$randomName`"
fails a query.
Posted: Tue May 25, 2004 12:43 am
by kevin7
hmm... u means if a error message come out... means.. the table is exist?
Posted: Tue May 25, 2004 12:44 am
by feyd
yep
Posted: Tue May 25, 2004 12:53 am
by kevin7
how can i capture the error message?
i'm a newbie...
tq
Posted: Tue May 25, 2004 12:56 am
by feyd
Code: Select all
$check = mysql_query("CREATE TABLE `$randomName`") or -1;
if($check === -1)
{// it existed
}
else
{// it was created
}
Posted: Tue May 25, 2004 2:42 am
by mendingo
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
}
Posted: Tue May 25, 2004 2:44 am
by feyd
read the post:
kevin7 wrote:i want to make a table that is randomly generated using php...