"called with 10 bind variables when 0 are needed at" に対する対処法 [エラー]

MSG:DBD::mysql::st execute failed: called with 10 bind variables when 0 are needed at
..

→原因は "(ダブルクオーテーション) と '(シングルクォーテーション) の違いです.




例えば, $hoge を "(ダブルクオーテーション)でくくると, $hoge の中身が展開されるのに対し, '(シングルクォーテーション) では $hoge は変数としてではなくただの文字列として扱われるのです.

よって, DBI を書くときで, SQL文をヒアドキュメントで挿入するときには要注意です.

こういう時は "(ダブルクオーテーション)を使う.

my $ret = $dbh->selectall_hashref(<<"SQL");
select hoge,fuga $rows from data where hoge in ($piyo);
SQL


こういう時は, '(シングルクォーテーション)

my $sth = $dbh->prepare(<<'SQL');
select fuga from data where hoge=?
SQL

Ref.
http://www.aimix.jp/cgi/syohomzretu.html