Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: perl DBI LOAD DATA INFILE

by poj (Curate)
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 musing on the Monastery: (13)
As of 2014-04-18 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls