in reply to Re: Search a SQL Table and Delete Records
in thread Search a SQL Table and Delete Records
poj#!perl use DBI; use strict; my $dbh = get_dbh(); # connect to db # build regex my @keyword = qw(www http .com); my $words = join '|',@keyword; my $regexp = qr/$words/i; print "Regular Expression is $regexp\n"; # search for key words my $sql = 'SELECT comment_ID,comment_content FROM wp_comments'; my $sth = $dbh->prepare($sql); $sth->execute(); my @spam = (); while (my ($id,$content) = $sth->fetchrow_array()) { if ($content =~ /$regexp/ ){ print "ID : $id\ncomment : $content\n\n"; push @spam,$id; } } # delete records my $sql_del = 'DELETE FROM wp_comments WHERE comment_ID = ?'; my $sth_del = $dbh->prepare($sql_del); for my $id (@spam){ # enable this when you are sure it's working !! #$sth->execute($id); print "Deleted $id\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Search a SQL Table and Delete Records
by Anonymous Monk on Aug 30, 2014 at 18:25 UTC | |
|
Re^3: Search a SQL Table and Delete Records
by Katanya (Novice) on Sep 20, 2014 at 07:06 UTC |