Jochem, > what is the context of the code you posted? ... in a function? class? part > of an app? > whats its purpose?
A singular, tutorial example I put together to show a basic way to connect and write if the table exists, if not create table. > why do you need to check/create the table dynamically? Newbie protection. > why do you think the way its done now is 'bad'? I'm not that skilled. Just checking with real coders. I'm more of a well-meaning academic who wants to share an idea with other teachers and show them an easy, applicable example of sending score results to a mysql server. It's part of a bigger tutorial: http://compcanlit.usherbrooke.ca/eslcafe/hotpotatoes/hot-potatoes_104.htm I'm still working on it. > >>John Taylor-Johnston wrote: > >>I've read: > >>>http://dev.mysql.com/doc/mysql/en/create-table.html > >>Would 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 EXISTS `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';"; > >>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); -- John Taylor-Johnston ----------------------------------------------------------------------------- °v° Bibliography of Comparative Studies in Canadian, Québec and Foreign Literatures /(_)\ Université de Sherbrooke ^ ^ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php