I want to check if the database already exist before creating it, if yes -> say it exist, if no -> create a new one, if error occured -> echo it. This is what i got for now, what should i add to complete the statement? if (mysql_query("CREATE DATABASE ".$dbname,$dbcnx)); { echo "Database created: " . $dbname; } else { echo "Error creating database: " . die (mysql_error($dbcnx)); } ?> PHP:
i think you can do conditional statements in mysql ex create if not exist SOME_TABLE Code (markup): I don't think that is the exact sytax, but google for the create sytax and check it out on mysqls documentation site.
Pretty simple method: $result = mysql_query(" SHOW TABLES LIKE '".$dbname."' "); if( mysql_num_rows($result) ) { echo "Table exists"; } else { echo "Table does not exist"; } PHP: