#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use CGI;

# Create a new CGI object
my $cgi = CGI->new;

# Print the HTTP header indicating content type as text/html
print $cgi->header('text/html');



print "<html><head><title>Hello, Perl!</title></head><body>";
print "<p>Hello Perl $]</p>";





# MySQL database configurations
my $db_host = "localhost";
my $db_name = "plankzeil";
my $db_user = "plankzeil";
my $db_pass = "Kiv9Fref";

# Establish database connection
my $dbh = DBI->connect("DBI:mysql:$db_name:$db_host", $db_user, $db_pass, {
    PrintError => 1,
    RaiseError => 1,
    AutoCommit => 1
});

# Check for connection errors
if (!$dbh) {
    die "Error connecting to database: " . DBI->errstr;
}

# Perform database query
my $query = "SELECT * FROM test";
my $sth = $dbh->prepare($query);
$sth->execute();

# Fetch and print results
while (my $row = $sth->fetchrow_hashref) {
    print "ID: $row->{id}, Name: $row->{name}<br/>";
}

# Disconnect from the database
$sth->finish();
$dbh->disconnect();

print "</body></html>";
