tunafish has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Mysql DBI placeholders not working
by bitingduck (Deacon) on Mar 17, 2015 at 05:27 UTC | |
|
Re: Mysql DBI placeholders not working
by Anonymous Monk on Mar 17, 2015 at 03:42 UTC | |
|
Re: Mysql DBI placeholders not working
by Laurent_R (Canon) on Mar 17, 2015 at 07:10 UTC | |
|
Re: Mysql DBI placeholders not working
by choroba (Cardinal) on Mar 17, 2015 at 10:05 UTC | |
by Anonymous Monk on Mar 17, 2015 at 10:10 UTC |