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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |