#!/usr/bin/perl -w

# $Id: dbi_simple.perl,v 1.1 2004/11/08 21:56:47 jari Exp $

use strict;
use CGI;
use Data::Dumper;
use DBI;

# prepare for html output.
my $cgi=new CGI;
print($cgi->header(),
      $cgi->start_html(-title => "Database information"));

# do the database query
my $dbh = DBI->connect("DBI:mysql:acid_test:localhost","acid_user","");
my $sth = $dbh->prepare("SELECT * FROM species");
$sth->execute();

# extract information from query
my @species;
print "<pre>";
while(my $row = $sth->fetchrow_hashref()) {
    # print statements here are just for educational purposes
    print "Reference $row, dumper results:\n";
    print Dumper($row);
    # here we do the extraction of species names
    push(@species,$row->{'name'});
}
print "</pre>";

# print result of query
print "<p><table border=1>";
print "<tr><td><b>Species</b></td>";
foreach my $str (@species) {
    print "<tr><td>$str</td></tr>";
}
print "</table></p>\n";

# finish html output.
print($cgi->end_html());
