Solution: Bind variables should be an ARRAY, not an ARRAY REFERENCE. Original post follows:

It's the most bizarre thing. I've no idea what is going wrong.

I have the following code:

my $sql='UPDATE products SET sku=? WHERE sku=?'; my $sql_values = [$sku, $old_sku]; $dbh->do($sql, undef, $sql_values);

This fails with the error:

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 righ +t syntax to use near '' at line 1 at ...

However, the following code works fine:

my $sql='UPDATE products SET sku="'.$sku.'" WHERE sku="'.$old_sku.'"'; $dbh->do($sql);

Of course, I want to use placeholders in my SQL. I've been staring at this for the past 4 hours and have no clue what's going on. I don't even know where to begin Googling. This is incredibly bizarre. Elsewhere in the code, placeholders are working just dandy.

Edited to Add: Wow, I'm a moron. The bind variables should be an array, not an array reference... and all it took for me to figure that out was RTFM. Apologies for wasting your time, dear monks. I'd delete this node if I could.


In reply to [Solved] Mysql DBI placeholders not working by tunafish

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.