create if table not exists
| From: | John Taylor-Johnston | Date: | Mon, 17 May 2004 05:13:31 +0000 |
| Subject: | create if table not exists | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-186376@lists.php.net to get a copy of this message | ||
How can I check if a table exists in a mysql db. If it table does not exist, then,
$news = mysql_query($sql_create);
else
$news = mysql_query($sql);
Not sure I know where to start?
-----snip--------
$server = "localhost";
$user = "user1";
$pass = "****";
$db="user1table";
$table="comments";
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
$sql = 'SELECT * FROM '.$table.' WHERE MATCH (username) AGAINST
(\''.stripslashes($searchenquiry).'\' IN BOOLEAN MODE) ORDER BY id asc;';
$sql_create = "CREATE TABLE ".$table." (
id int(11) NOT NULL auto_increment,
username varchar(100) NOT NULL,
comment text,
PRIMARY KEY (id)
);
Sorry, I'm not even sure if this is a php thing as much as it is also mysql.
-
John