Re: Re: Different approach?
| From: | Jochem Maas | Date: | Mon, 21 Mar 2005 22:08:21 +0000 |
| Subject: | Re: Re: Different approach? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-211215@lists.php.net to get a copy of this message | ||
John Taylor-Johnston wrote:
Sorry to bother. I was hoping for inspiration. The code works. I wonder if there is a cleaner way?what is the context of the code you posted? ... in a function? class? part of an app? whats its purpose? why do you need to check/create the table dynamically? why do you think the way its done now is 'bad'? rgds, Jochem
John Taylor-Johnston wrote: Hi, I've read:http://dev.mysql.com/doc/mysql/en/create-table.htmlWould anyone code/approach this differently? ################################################# $server = "localhost"; $user = "myname"; $pass = "mypass"; $db = "mydb"; $table = "demo_assignment1"; ################################################# $myconnection = mysql_connect($server,$user,$pass); ################################################# $sql = "CREATE TABLE IF NOT EXISTSdemo_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';"; mysql_select_db($db,$myconnection); mysql_query($sql) or die(print mysql_error()); ################################################# $sql = "INSERT INTO $table (StudentNumber,Exercise1,Exercise2) values ('$StudentNumber','$Exercise1','$Exercise2')"; mysql_select_db($db,$myconnection); mysql_query($sql) or die(print mysql_error()); mysql_close($myconnection);