Reply to if table not exists

Your name:

Reply:


Posted by John Taylor-Johnston on 03/15/05 23:29

How do I get PHP to create a table, if one does not already exist?

I have to do something with:

$news = mysql_query($sql) or die(print mysql_error());

What can I also add something to $sql?

$sql = "if not exists CREATE TABLE `demo_assignment1` ...

John


--------snip--------

$server = "localhost";
$user = "myname";
$pass = "mypass";
$db = "mydb";
$table = "demo_assignment1";

############################################
## What do I add here?
############################################

$sql = "CREATE TABLE `demo_assignment1` (
`StudentNumber` varchar(8) NOT NULL default '',
`Exercise1` varchar(100) NOT NULL default '',
`Exercise2` varchar(100) NOT NULL default '',
`TimeStamp` timestamp(14) NOT NULL,
PRIMARY KEY (`TimeStamp`)
) TYPE=MyISAM COMMENT='place something here';";

$myconnection = mysql_connect($server,$user,$pass);

mysql_select_db($db,$myconnection);

############################################
## What do I do here?
$news = mysql_query($sql) or die(print mysql_error());
############################################


#if table exists, I will now

$sql = "INSERT INTO $table (StudentNumber,Exercise1,Exercise2)
values ('$StudentNumber','$Exercise1','$Exercise2')";
mysql_select_db($db,$myconnection);
mysql_query($sql) or die(print mysql_error());

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация