Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to perl DBI LOAD DATA INFILE by nickd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-28 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found