Mailinglisten-Archive |
Hallo
ich experimentiere seit einigen Tagen mit Datenbank-abfragen aus
CGI-Scripts.
Um eine einfache Umgebung zu haben, habe ich mir ein Script
geschrieben, dass in einer HTML-Textarea einen Select-Befehl
entgegen nimmt und das Ergebnis als Tabelle ausgibt. Das soll dann
spaeter ausgebaut werden.
Das funktioniert auch.
Allerdings tritt folgendes Problem auf: Wenn ich das Script mehrfach
hintereinander ausfuehre, bleibt irgendwann die Ergebnis-Tabelle
leer. Ein paar Klicks auf das Submit-Button foerdert dann irgendwann
wieder Daten zutage. Ich habe keine Idee, woran diese Phaenomen
liegen kann.
Ich arbeite unter Linux 6.1 mit Apache 1.3
Mein Script sieht folgendermassen aus:
################
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use strict;
use CGI;
use DBI;
my $value="";
my $doc="";
my _(at)_row=();
my $sql="";
my $table="";
my $color="white";
my $query = CGI::new();
$sql = $query->param("SQLtext");
showdata($sql) if $sql ne "";
$doc=<<"END";
<html>
<head><title>SQL-Abfrage</title></head>
<body>
<form action="http://192.168.0.99/cgi-bin/sqltool.pl" method=post>
<textarea cols=50 rows=10 name="SQLtext">$sql</textarea>
<input type=submit value="absenden">
</form>
$sql<br><br>
$table
</body>
</html>
END
print $query->header();
print $doc;
sub showdata($sql)
{
my $SQL = shift;
my $con=DBI->connect('DBI:mysql:walhus:hauptrechner.linux.mb:3306',
'michael', '',
{ PrintError => 1, AutoCommit =>1 });
my $sth=$con->prepare($SQL);
$sth->execute();
$table="<table border=0 cellspacing=0 cellpadding=3>";
while (_(at)_row=$sth->fetchrow_array){
$table=$table."<tr>";
if ($color eq "white"){
$color="lightgrey";
}
else {
$color="white";
}
foreach $value (_(at)_row){
$value= " \;" if $value eq "";
$table=$table."<td bgcolor=\"$color\">$value</td>";
}
$table=$table."</tr>\n";
}
$sth->finish();
$con->disconnect();
$table=$table."</table>";
}
##########################
Danke fuer Hinweise
Michael
--
Michael Baumeister
E-mail: m.baumeister_(at)_t-online.de
---
*** Abmelden von dieser Mailingliste funktioniert per E-Mail
*** an mysql-de-request_(at)_lists.4t2.com mit Betreff/Subject: unsubscribe
php::bar PHP Wiki - Listenarchive