in reply to Perl DBI adding some, not all, records to MySQL database

jettero's solution will fix you right up. You are doing a straight string substitution in your SQL, which is bad. Using prepare() and binding your column values will magically take care of things like escaping that pesky single quote in the record being skipped.
  • Comment on Re: Perl DBI adding some, not all, records to MySQL database

Replies are listed 'Best First'.
Re^2: Perl DBI adding some, not all, records to MySQL database (Thank you!)
by ericlee (Novice) on Jul 09, 2007 at 10:42 UTC

    It took a while, but this all eventually worked. The problem was almost certainly the single apostrophe, which I hadn't noticed. The code I'm using now reads:

    my $sth = $db->prepare("insert into news(url, header, country, country +2, date, priority, userid, source, formoreinfo, language, regreqd, ke +ywords, image, actnowcampaigncode, state) values(?,?,?,?,?,?,?,?,?,?, +?,?,?,?,?)"); foreach $record (@records) { $n++; &splitupintofields; if ($priority > 0) { $y++; &convdate; &convlang; $sth->execute($url, $header, $country1, $country2, $date, $pri +ority, $correspondent, $source, $formoreinfo, $language, $regreqd, $k +eywords, $image, $actnowcampaigncode, $state); } } $db->disconnect();