Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: perl DBI LOAD DATA INFILE

by poj (Priest)
on Oct 14, 2013 at 13:50 UTC ( #1058186=note: print w/ replies, xml ) Need Help??


in reply to perl DBI LOAD DATA INFILE

Most DBDs won't allow placeholders for a table name. Try using variable interpolation. For example ;

#!/usr/bin/perl use strict; use DBI; my $db_table = 'test1'; my $dbh = dbh();# connect code as required #my $count = $dbh->do("DELETE FROM $db_table"); #print "$count lines deleted from $db_table\n"; my $sql = <<SQL; LOAD DATA LOCAL INFILE ? INTO TABLE $db_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1, field2, field3); SQL my $count = $dbh->do($sql,undef,'importfile.csv'); print "$count lines inserted into $db_table\n"; my $sql = qq{ SELECT * FROM $db_table }; my $sth = $dbh->prepare($sql); $sth->execute(); while (my @f = $sth->fetchrow_array){ print "@f\n"; }
poj


Comment on Re: perl DBI LOAD DATA INFILE
Download Code
Re^2: perl DBI LOAD DATA INFILE
by nickd (Initiate) on Oct 14, 2013 at 17:42 UTC

    Dear POJ, Your suggestion worked. Thanks a lot for your help and suggestion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2015-07-03 13:42 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 (53 votes), past polls