Front page | perl.beginners |
Postings from September 2009
some errors in databasescript
Thread Next
From:
Ruprecht Helms
Date:
September 17, 2009 01:46
Subject:
some errors in databasescript
Message ID:
4AB1F3FA.4040704@rheynmail.de
Hi,
I've written a little perlscript that should write the output of
databasetables into a textfile. But unfortunately I get some
syntaxerrors that a least I'm not able to reproduce.
syntax error at ./statistik.pl line 73, near "} or"
syntax error at ./statistik.pl line 82, near ") {"
syntax error at ./statistik.pl line 86, near "} or"
Missing right curly or square bracket at ./statistik.pl line 100, at end
of line
Execution of ./statistik.pl aborted due to compilation errors.
Here the scriptcode:
#!/usr/bin/perl -w
open (STATISTIKDATA,">>statistik.txt");
use DBI;
$nutzer='root';
$password='';
my $data_source = "dbi::mysql:Cycosmos";
my $dbh = DBI->connect($data_source, $nutzer, $password)
or die "Can't connect to $data_source: $DBI::errstr";
my $sth = $dbh->prepare( q{
SELECT name, vorname, firma
FROM user
}) or die "Can't prepare statement: $dbh->errstr";
my $rc = $sth->execute
or die "Can't execute statement: $dbh->errstr";
my $sth1 = $dbh->prepare( q{
SELECT * FROM User WHERE an_user=$user
}) or die "Can't prepare statement: $dbh->errstr";
my $sth2 = $dbh->prepare( q{
SELECT * FROM User_Kontakte_unbestaetigt WHERE von_user=$user
}) or die "Can't prepare statement: $dbh->errstr";
print "Query will return $sth->{NUM_OF_FIELDS} fields.\n\n";
print "Field names: @{ $sth->{NAME} }\n";
while (($name, $vorname, $firma) = $sth->fetchrow_array) {
print STATISTIKDATA "$vorname $name\n";
print STATISTIKDATA "$firma\n";
}
die $sth->errstr if $sth->err;
while (($name, $vorname, $firma) = $sth1->fetchrow_array) {
print STATISTIKDATA "$vorname $name von $firma\n";
print STATISTIKDATA "Wuenscht mit Ihnen Kontakt aufzunehmen\n\n";
# check for problems which may have terminated the fetch early
die $sth1->errstr if $sth1->err;
$a = 0;
while (($name) = $sth2->fetchrow_array) {
$a = $a + 1;
}
print STATISTIKDATA "Ihre Kontaktanfragen in der Woche: ".$a;
# Anzahl von privaten Nachrichten in der Woche
my $sth3 = $dbh->prepare( q{
SELECT * FROM User_Nachrichten WHERE an_User=$user
}) or die "Can't prepare statement: $dbh->errstr";
#Profilabrufe innerhalb der Woche
my $sth4 = $dbh->prepare( q{
SELCECT User.ID,Vorname,Name,Firma FROM User_Profilaufruf INNER JOIN
User ON User.ID=User_Profilaufruf.von_User WHERE von_User=$user LIMIT 4
}) or die "Can't prepare statement: $dbh->errstr";
while (($id,$Vorname,$Name,$Firma) = $sth4->fetchrow_array) {
print STATISTIKDATA "$Vorname $Name von $Firma hatte Ihr Profil
besucht\n";
print STATISTIKDATA "<a
href='http://www.b-net-c.de/adressbuch/$Vorname_$Name_$id.html'>Link zum
Profil</a>\n";
print STATISTIKDATA "\n";
} or die "Can't execute statement: $dbh->errstr";
#Events an denen Sie teilnehmen
my $sth5 = $dbh->prepare( q{
SELECT * FROM User_Termin INNER JOIN Termin ON
User.ID=User_Termin.userid WHERE userid=$user
});
while (($Betreff,$Startdatum,$Startzeit,$Enddatum,$Endzeit,$Ort) =
$sth5->fetchrow_array) {
print STATISTIKDATA "$Betreff am / von $Startdatum um $Startzeit
bis $Enddatum um $Endzeit in $Ort\n";
} or die "Can't execute statement: $dbh->errstr";
#Geburtstage Ihrer Kontakte innerhalb dieser Woche
my $sth6 = $dbh->prepare( q{
SELECT User.ID,Vorname,Name,$Geburtstag FROM User INNER JOIN
User_Kontakt ON User.ID=User_Kontakt.von_USER WHERE EXTRACT(DAY FROM
`Geburtstag`)>=EXTRACT(DAY FROM CURDATE()) AND EXTRACT(DAY FROM
`Geburtstag`)<= EXTRATE (DAY FROM DATE_ADD(CURDATE(), INTERVAL 7 DAY)
}) or die "Cant prepare statement: $dbh->errstr";
while (( $Vorname, $Name, $Geburtstag) = $sth5->fetchrow_array) {
print STATISTIKDATA "Vorname $Name am $Geburtstag\n";
}
$dbh->disconnect;
Thread Next
-
some errors in databasescript
by Ruprecht Helms