Leser: 1
6 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
$sth = $dbh->prepare('select * from tabelle');
$sth->execute;
print OUT '<table border=1>';
while ( $rv = $sth->fetchrow_hashref )
{
if ( $i )
{
$i = 0;
print OUT '<tr>';
foreach (keys(%$rv) ) { print OUT '<td>'.$_.'</td>'; }
print OUT '</tr>'."\n";
}
print OUT '<tr>';
foreach (values(%$rv) )
{
print OUT '<td>';
if ( defined($_) )
{
print OUT $_;
}
else
{
print OUT ' ';
}
print OUT '</td>';
}
print OUT '</tr>'."\n";
}
print OUT '</table>';
$sth->finish;
QuoteThe keys are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the values or each function produces...
1
2
3
4
5
$arrayref = $sth->{NAME};
# oder
$arrayref = $sth->{NAME_lc};
# oder
$arrayref = $sth->{NAME_uc};
1
2
3
4
5
6
7
8
9
10
11
12
13
my $dbh = DBI->connect($data_source, $username, $auth, {RaiseError => 1});
my $sth = $dbh->prepare('select * from table');
print qq~<table border="1">\n<tr>\n~;
print map "<th>$_</th>\n", @{$sth->{NAME}};
print "</tr>\n";
while (my $arrayref = $sth->fetchrow_arrayref) {
print "<tr>\n";
print map "<td>$_</td>\n", map +(defined($_) ? $_ : 'NULL'), @$arrayref;
print "</tr>\n";
}
print "</table>\n";
$sth->finish;
$dbh->disconnect;
1
2
3
4
5
6
7
print map "<th>$_</th>\n", @{$sth->{NAME}};
print "</tr>\n";
while (my $arrayref = $sth->fetchrow_arrayref) {
print "<tr>\n";
print map "<td>$_</td>\n", map +(defined($_) ? $_ : 'NULL'), @$arrayref;
print "</tr>\n";
}
6 Einträge, 1 Seite |