当先锋百科网

首页 1 2 3 4 5 6 7
#!/usr/bin/perl


use strict;
use DBI;

my $host = "localhost";
my $port = "3306";
my $driver = "mysql";
my $database = "mysql";

my $dsn = "DBI:$driver:database=$database:$host:$port";
my $username = "root";
my $password = "*******";

my $dbh = DBI->connect($dsn, $username, $password) or die $DBI::errstr;
my $sth = $dbh->prepare("select host, user from user");

$sth->execute();

print "Content-type:text/html\r\n\r\n";

print '<html>';
print '<head>';
print '<title>cgi test </title>';
print '</head>';

print '<body>';
#print '<h2> this is a cgi test.</h2>';
print '<table >';
while(my @row = $sth->fetchrow_array()){
	print "<tr>";
	print '<td>'.join('</td><td>', @row)."</td>";
	print "</tr>";
}
print '</table>';
print '</body>';
print '</html>';

$sth->finish();
$dbh->disconnect();