Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Perl DBI adding some, not all, records to MySQL database

by webfiend (Vicar)
on Jul 06, 2007 at 19:20 UTC ( #625331=note: print w/replies, xml ) Need Help??


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();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://625331]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2019-07-19 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?