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(); $getcountqry->execute($botid) or die $dbh->errstr(); my $getcount = $getcountqry->fetchrow_arrayref(); if($getcount->[0] == 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(); } elsif ($getcount->[0] == 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(); } }