Thread DBI-Mysql Problem (2 answers)
Opened by Mindfoo at 2009-04-07 21:06

Mindfoo
 2009-04-07 21:06
#120365 #120365
User since
2009-04-03
10 Artikel
BenutzerIn
[default_avatar]
Hallo!
Ich möchte ein paar sql-statements im script einbauen:

am anfang prüfen ob die botid in der datenbank schon vorhanden ist
wenn nein: werte neu eintragen
wenn ja: werte updaten

ich bekomme als $getcount komischerweise immer 1 zurück obwohl der table leer ist, ausserdem werden die sql inserts/updates nicht durchgeführt, ich bekomm aber keinen fehler?! :(

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub dbwritebots {
    my $count = counter();
    my $dbh = DBI->connect( $connectionInfo, $dbuser, $dbpass )
      or die "Can.t connect to the DB: $DBI::errstr\n";
    my $getcountqry = $dbh->prepare("SELECT COUNT( * ) FROM bots WHERE id=?")
      or die $dbh->errstr();
    my $getcount = $getcountqry->execute($botid) or die $dbh->errstr();
    if($getcount == 0){
      my $sth = $dbh->prepare("INSERT INTO bots SET id=?, botqauth=?, processed=?")
        or die $dbh->errstr();
      $sth->execute($botid, $qauth, counter()) or die $dbh->errstr();
      $dbh->disconnect();
    } elsif ($getcount == 1){
      my $sth = $dbh->prepare("UPDATE bots SET botqauth=?, processed=? WHERE id=?")
        or die $dbh->errstr();
      $sth->execute($qauth, counter(), $botid) or die $dbh->errstr();
      $dbh->disconnect();
      }
}

View full thread DBI-Mysql Problem