Re: create if table not exists
| From: | John Taylor-Johnston | Date: | Mon, 17 May 2004 06:29:47 +0000 |
| Subject: | Re: create if table not exists | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186385@lists.php.net to get a copy of this message | ||
I used phpmyadmin to help generate some code. When I add:
IF NOT EXISTS
mhinse_counter it mysql_errors that the error is around:
"IF NOT EXISTS mhinse_counter CREATE TABLE mhinse_counter (
"
Can anyone see clear here?
$server = "localhost";
$user = "user1";
$pass = "******";
$db="jtjohnston";
$table="mhinse_counter";
$query = 'IF NOT EXISTS mhinse_counter
CREATE TABLE mhinse_counter ( id int( 10 ) NOT NULL AUTO_INCREMENT ,'
. ' IPAddress varchar( 100 ) NOT NULL default \'\','
. ' RemoteHost varchar( 100 ) NOT NULL default \'\','
. ' Language text NOT NULL ,'
. ' StampDate date NOT NULL default \'0000-00-00\','
. ' StampTime time NOT NULL default \'00:00:00\','
. ' TimeStamp timestamp( 14 ) NOT NULL ,'
. ' PRIMARY KEY ( id ) ) TYPE = MYISAM AUTO_INCREMENT =1';
$myconnection = mysql_connect($server,$user,$pass);
mysql_select_db($db,$myconnection);
mysql_query($query) or die(print mysql_error());
> Tim Van Wassenhove wrote:
> > How can I check if a table exists in a mysql db.
> $query = 'IF NOT EXISTS table CREATE TABLE table (......)';
> mysql_query($query);