in reply to Re^3: Using perl to Create a Table in a Database
in thread Using perl to Create a Table in a Database
So you mean like this...?
#!/usr/bin/perl use strict; use CGI qw(:standard); use DBI; print "Content-type: text/html\n\n"; my $database="assignments"; my $username="web320"; my $password=""; my $fieldname=param('fieldname'); my $fieldtype=param('fieldtype'); my $fieldlength=param('fieldlength'); my $table=param('table'); my $field=param('field'); my $f; for ($f=1;$f<=$field;$f++) { my $fieldname=param('fieldname' .$f); my $fieldtype=param('fieldtype' .$f); my $fieldlength=param('fieldlength' .$f); } #connect to database my $dsn="DBI:mysql:$database:localhost"; my $dbh=DBI->connect($dsn,$username) or die print "doesn't work"; #if +use password, put ,$password my $query = "CREATE TABLE $table ($fieldname $fieldtype ($fieldlength) +)"; #prepare and execute my $sth=$dbh->prepare($query) or die print "bad query"; #$sth->execute(); print $query;
the only problem i have left now is that it only prints the tablename ($table) and not $fieldname, $fieldtype, $fieldlength i.e. CREATE TABLE test (())
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Using perl to Create a Table in a Database
by kcott (Archbishop) on Nov 04, 2010 at 17:57 UTC | |
by mynameisG (Novice) on Nov 04, 2010 at 22:13 UTC |