Leser: 1
2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! d:/Programme/Perl/bin/perl
use strict;
use warnings;
use CGI ();
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use DBI;
use vars qw($CsvPath);
$CsvPath = 'c:/Programme/ApacheGroup/Apache/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~
<center>
<h1>Suchergebnis:</h1>
<hr />
<table border="2">
<tr>
<td width="200"><b>Kundennummer:</b></td>
<td width="200"><b>Adresse:</b></td>
<td width="200"><b>Name:</b></td>
<td width="200"><b>Telefonnummer:</b></td>
<td width="200"><b>Rechnungsbetrag:</b></td>
</tr>\n~;
while( my @data = $sth->fetchrow() ) {
printf qq~
<tr>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
<td><b>%s</b></td>
</tr>\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
2 Einträge, 1 Seite |