Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: DBI and Inserting an Array

by The Mad Hatter (Priest)
on Mar 12, 2004 at 00:24 UTC ( #336038=note: print w/ replies, xml ) Need Help??


in reply to DBI and Inserting an Array

Kinda close (and that example you gave would throw a bunch of syntax errors, but I'm going to assume you know how to use the DBI; if you don't, read the doc and many tutorials here on this site).

Here's how I would do it:

my $dbh = DBI->connect( ... ); # fill in the arguments you need my $sth = $dbh->prepare(<<'SQL'); INSERT INTO ads (lname,fname,item,price,street,city,state,zip) VALUES (?,?,?,?,?,?,?,?) SQL while (my $line = <SOME_FILEHANDLE>) { # ... parse $line to get data in @array... you've done this # assuming @array contains 8 values, this inserts the data $sth->execute(@array); }

You'd want to check for errors on the insert though if you don't have RaiseError or an error handler in place.


Comment on Re: DBI and Inserting an Array
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-07-04 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls