jdlev has asked for the wisdom of the Perl Monks concerning the following question:
#QUERY PREPARATION
my $query = sprintf("INSERT INTO email VALUES (%d, %s)",
$servproID, $dbh->quote("$address"));
$dbh->do($query);
Here is the FULL CODE:
use Regexp::Common qw(Email::Address);
use Email::Address;
use DBI;
my $dsn = 'dbi:mysql:servpro:localhost:3306';
my $db = 'servpro';
my $host = 'host';
my $user = 'user';
my $password = 'pass';
my $address = ($addresses[0]);
# DATABASE HANDLE
my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host",
$user, $password, {RaiseError => 1});
#QUERY PREPARATION
my $sth = $dbh->prepare("select servproID from fran");
$sth->execute;
while(@row = $sth->fetchrow_array()) {
foreach $row(@row) {
my $filename = "C:/Test/email/$row.txt";
open my $rh, '<', $filename or die "$filename: $!";
my @addresses =
map { m/mailto:($RE{Email}{Address})/o; $1 }
grep { m/href=.+?mailto:/ }
<$rh>
;
close $rh;
{
local $, = local $\ = "\n";
chop(@addresses);
print "$row : @addresses";
#QUERY PREPARATION
my $query = sprintf("INSERT INTO email VALUES (%d, %s)",
$servproID, $dbh->quote("$address"));
$dbh->do($query);
}
}
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Database Error? DBD:MySQL:DB DO failed: Duplicate entry '0' for key '1' at
by Corion (Patriarch) on Dec 30, 2008 at 18:14 UTC | |
|
Re: Database Error? DBD:MySQL:DB DO failed: Duplicate entry '0' for key '1' at
by jeffa (Bishop) on Dec 30, 2008 at 18:10 UTC | |
|
Re: Database Error? DBD:MySQL:DB DO failed: Duplicate entry '0' for key '1' at
by CountZero (Bishop) on Dec 30, 2008 at 22:13 UTC |