Re: if table not exists
| From: | Steve Buehler | Date: | Wed, 16 Mar 2005 00:31:11 +0000 |
| Subject: | Re: if table not exists | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210864@lists.php.net to get a copy of this message | ||
http://dev.mysql.com/doc/mysql/en/create-table.html
At 03:29 PM 3/15/2005, John Taylor-Johnston wrote:
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 TABLEdemo_assignment1... John --------snip-------- $server = "localhost"; $user = "myname"; $pass = "mypass"; $db = "mydb"; $table = "demo_assignment1"; ############################################ ## What do I add here? ############################################ $sql = "CREATE TABLEdemo_assignment1(StudentNumbervarchar(8) NOT NULL default '',Exercise1varchar(100) NOT NULL default '',Exercise2varchar(100) NOT NULL default '',TimeStamptimestamp(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()); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php