http://www.perlmonks.org?node_id=1058110

nickd has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am relatively new to perl and this forum. I am trying to use perl DBI for mySql LOAD DATA INFILE statement to upload a csv file to a mySQL database. However, the execute statement returns an undef value. However if i use a select or desc statement, it works fine.

#!/usr/bin/perl -w use strict; use warnings; use File::Basename; use DBI; use DBD::mySQL; my $data_path="D:\\NickD\\Project\\StockData\\"; my $db = "TestMMDB"; my $user = "user"; my $pass ="pass"; my $host = "localhost"; my $query =""; my @row; ## First get all files to upload, scan names, identify table to be upl +oaded in my @files = glob("$data_path*.csv"); DBI->trace(1); ## Connect to the database my $dbh = DBI->connect("dbi:mysql:$db:$host",$user,$pass); ## Gather the files to upload to DB foreach my $file(@files){ my $filename = basename($file); my ($db_table,$date) = split("_",$filename); ## Create Query # $query ="SELECT * FROM $db.$db_table"; $query = q{LOAD DATA INFILE ? INTO TABLE ? FIELDS TERMINATED B +Y ',' (Date,Symbol,Open,High,Low,Close,Volume)}; my $sqlQuery = $dbh->prepare($query); my $rv = $sqlQuery->execute($file,$db.".".$db_table) or die "Oops! +: Can't execute the query :".$sqlQuery->errstr; while (@row = $sqlQuery->fetchrow_array()) { print "@row\n"; } } my $rc = $dbh->disconnect(); exit(0);

All help will be greatly appreciated.