Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: perl DBI LOAD DATA INFILE

by poj (Prior)
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

Replies are listed 'Best First'.
Re^2: perl DBI LOAD DATA INFILE
by nickd (Novice) 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?
[choroba]: "for tomorrow"
[Discipulus]: Let's perl: from cpan website how can thou/you tell how many namespaces are beyond App::* ?
[choroba]: Map of CPAN
[LanX]: cpan serach?
[Discipulus]: about bred: 'let our bred levitate (well)'
[Discipulus]: I love maps!
[Discipulus]: also App::* works in cpan search, i tried App::

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-11-23 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (338 votes). Check out past polls.

    Notices?