#! f:/Perl/bin/perl -w use strict; use CGI qw(:standard); use DBI; my $dbh = DBI->connect('DBI:ODBC:Kunden'); 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 = $dbh->prepare($sqlstatement); $sth->execute || die "Could not execute SQL statement ... maybe invalid?"; 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 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