in reply to Comparing 2 databases
Well, there are still pieces of your script missing, so I'm not sure I've captured all of the functionality, but try this...
#!/usr/bin/perl use strict; use warnings; use DBI; my $alertstable = $ARGV[0] || 'alertstable'; my $dbh = DBI->connect("DBI:mysql:database=dbname;host=sqlhost", 'username','password', {'RaiseError'=>1}); my $sth=&Do_SQL("Select * from bademails ORDER BY ID DESC"); while (my $pointer = $sth->fetchrow_hashref) { my $bademail = $pointer->{'email'}; my $sth2=&Do_SQL2("Select * from $alertstable where email LIKE '% +$bademail%'"); while (my $pointer2 = $sth2->fetchrow_hashref) { my $item = $pointer2->{'type'}; my $alertype = $pointer2->{'alertype'}; my $emaillist = $pointer2->{'email'}; my $ID = $pointer2->{'ID'}; my @emails = split /~~~/,$emaillist; my @goodmails = (); foreach my $address (@emails) { print "$ID<Br>\n"; if ($address ne $bademail) { push @goodmails,$address; } } if (scalar(@goodmails)) { my $newlist=join('~~~',@goodmails); $dbh->do("UPDATE $alertstable SET email='$newlist' WHERE t +ype='$item' and alerttype='$alertype';") || die $dbh->errstr; print "Updated $ID<Br>\n"; } } } # end while $dbh->disconnect; sub Do_SQL{ my ($SQL)=@_; my $sth; eval { $sth = $dbh->prepare($SQL); }; # check for errors if($@){ $dbh->disconnect; print "Content-type: text/html\n\n"; print "An ERROR occurred! $@\n"; exit; } else { $sth->execute; } return ($sth); }
You'll need to fix up the connect code to reflect your username and password for the database, and it was not clear what $alertable ever got set to, so make sure it is right.
Scott
|
|---|