- 论坛徽章:
- 0
|
下面是代码, 这段代码的目的显示employee表中的内容,并且显示在web上.
环境是:Tomact + mysql + perl.
现在运行的情况: 可以命令行到得结果,但是在web端不能得不到employee表中的内容.
use DBI;
use CGI;
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi -> header,
$cgi -> start_html ('perl connection mysql sample'),
$cgi -> h1 ('perl connection mysql sample'),
my $dbh = DBI->connect ("DBI:mysql:mytest:localhost","root","123456")|| die "Could not connect to database: ". DBI-> errstr;
my $sth = $dbh->prepare("SELECT * FROM employee");
$sth->execute();
my $results = $sth->fetchrow_hashref();
#print "Found a row: id = $results->{'id'}, name = $results->{'name'},role = $results->{'role'},location = $results->{'location'},email = $results->{'email'},pohne = $results->{'phone'},\n";
print $cgi -> table(
$cgi -> Tr( $cgi -> td(['id',$results->{'id'}]) ),
$cgi -> Tr( $cgi -> td(['name',$results->{'name'}]) ),
$cgi -> Tr( $cgi -> td(['role',$results->{'role'}]) ),
$cgi -> Tr( $cgi -> td(['location',$results->{'location'}]) ),
$cgi -> Tr( $cgi -> td(['email',$results->{'email'}]) ),
$cgi -> Tr( $cgi -> td(['phone',$results->{'phone'}]) ),
);
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
print $cgi -> end_html;
[ 本帖最后由 Miketanbin 于 2008-10-9 13:41 编辑 ] |
|