This is kind of an odd question, and I may even be doing something wrong that I am not aware of, but I am trying to use variables in a DBI do query for example:

my $columns = 'name,date'; my $values = 'Ben Marcata,2001-05-04'; my $placeholders = '?,?'; $dbh->do("insert into foo (source, $columns, status) values ($placehol +ders)", {}, 'file', $values, '' );
When I try to run my script I get this error from DBI: DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',)' at line 1 at hal9000.pl line 154, <$csvfile> line 2. Looking at my query I don't see where a rouge comma would be coming from. My reason for trying to do this is because I need to read data from multiple files and insert parts of it into a MySQL database. The order that the data is in differs between files so instead of trying to maintain a DBI do query for each file I would rather have one dynamic DBI query if possible.


In reply to Using variables in a DBI do queriy by vendion

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.