watagal Posted March 25, 2006 Share Posted March 25, 2006 Greetings,I just got my PHP script working to add a new table through mysql_query("CREATE TABLE ..."). Now I would like to add a PHP check to see if the table already exists. Can someone point me in the right direction?Thanks, WG Link to comment Share on other sites More sharing options...
Selacius Posted March 25, 2006 Share Posted March 25, 2006 Just do I query to select from the database before hand with the name of the table your looking for. Then also do an if statement to see if its valid.The code:$result = mysql_query("SELECT * FROM <database>");if (!$result) {echo "Table doesn't exist";}else {echo "Table Exists already";} Link to comment Share on other sites More sharing options...
watagal Posted March 25, 2006 Author Share Posted March 25, 2006 $result = mysql_query("SELECT * FROM <database>");Thanks, is there time penalty if the <database> does exists and have thousands of records?WG Link to comment Share on other sites More sharing options...
Selacius Posted March 25, 2006 Share Posted March 25, 2006 Not that I am aware. Your just checking to see if the table exists so sorry, that should be <table> and not <database>. So the only delay would probably be a very minute value. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now