MySQLテーブルのWEB表示

戻る

TMPLファイル #!C:/perl/bin/perl # showmysqltable1.pl use strict; use DBI; use CGI qw/:standard/; use HTML::Template; my $template = HTML::Template->new(filename => 'cook1.htm'); my @loop = (); my $dsn = "DBI:mysql:host=localhost;database=cookbook"; my $dbh = DBI->connect($dsn,"cbuser","cbpass") or die "Can't connect to server\n"; if(!$dbh) { print "SQL read ERROR!\n"; exit; } my $sth = $dbh->prepare("SELECT things,legs,arms FROM limbs"); $sth->execute; while ( my @arr = $sth->fetchrow_array ) { my %row = ( things => $arr[0], legs => $arr[1], arms => $arr[2] ); push(@loop, \%row); } $sth->finish; $dbh->disconnect; $template->param(THIS_LOOP => \@loop); print "Content-Type:text/html\n\n", $template->output; exit(0);

戻る