#! f:/Perl/bin/perl -w use strict; use warnings; use CGI (); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use DBI; use vars qw($CsvPath); $CsvPath = 'f:/Apache2/cgi-bin'; # oder besser, wenn Readonly vorhanden ist: # use Readonly $CsvPath => 'c:/Programme/ApacheGroup/Apache/cgi-bin'; my $cgi = CGI->new(); my %params = $cgi->Vars(); print $cgi->header(); if ( exists $params{suchanfrage} ) { &Suche ($cgi, \%params) } elsif( exists $params{eintrag} ) { &Eintragen($cgi, \%params) } else { &Startseite($cgi, '...') } print $cgi->end_html(); # ------------------------------------------------------------ sub Suche { my ($cgi, $params) = @_; my $dbh = &ConnectToDB(); $cgi->start_html('Antwort'); my $sqlStatement = qq~SELECT Tabelle1.Kundennummer, Tabelle1.Name, Tabelle1.Telefon, Tabelle2.Rechnungsbetrag FROM Tabelle2 JOIN Tabelle1 WHERE Tabelle2.Kundennummer = Tabelle1.Kundennummer~; my $sth = &FireSql($dbh, $sqlStatement); if ($sth->rows < 1) { print $cgi->p("Keine Daten gefunden"); return; } # if print qq~

Suchergebnis:


\n~; while( my @data = $sth->fetchrow() ) { printf qq~ \n~, @data[0, 1, 2, 3]; } # while $sth->finish(); $dbh->disconnect(); } # Suche # ------------------------------------------------------------ sub Eintragen { } # Eintragen # ------------------------------------------------------------ sub ConnectToDB { my $dsn = "DBI:CSV:Kunden.mdb=$CsvPath"; my $dbh = DBI->connect($dsn) or die "Error: couldn't connect to '$dsn': $DBI::errstr\n"; return $dbh; } # ConnectToDb # ------------------------------------------------------------ sub FireSql { my ($dbh, $sqlStatement, @values) = @_; my $sth = $dbh->prepare($sqlStatement) or die "Error: couldn't prepare sql: $DBI::errstr\n$sqlStatement\n"; $sth->execute(@values) or die "Error: couldn't execute sql: $DBI::errstr\n$sqlStatement\n"; return ($sth); } # FireSql # ------------------------------------------------------------
Kundennummer: Adresse: Name: Telefonnummer: Rechnungsbetrag:
%s %s %s %s