DBD::mysql 4.005 の痛いバグです。報告されてるのはコメント内にシングルクォートがある場合ですが、以下のSQLも実行出来ません。
select 'ab\'c' ,?
以下はセーフです。
select ?, 'ab\'c' /* クエスションが先 */
select 'a\'b\'c' ,? /* 偶数個のクォート */
$dbh->quote()と$sth->bind()を組み合わせると、この問題が起こりやすくなります。
use strict; use DBI; my $dbh = DBI->connect('dbi:mysql:...略...', 'user', 'pass') || die DBI->errstr; my $sql = sprintf(<<__SQL__, $dbh->quote(q/ab'c/)); select %s, ? __SQL__ my $sth = $dbh->prepare($sql) || die $dbh->errstr; $sth->execute(q/ef'g/) || die $sth->errstr; while(my $ref = $sth->fetch()){ print join("\t", @$ref), "\n"; } $dbh->disconnect() || die $dbh->errstr();
結果は、
DBD::mysql::st execute failed: called with 1 bind variables when 0 are needed at mysqlbug.pl line 10. called with 1 bind variables when 0 are needed at mysqlbug.pl line 10.
でした。
2008/1/14 追記。まだ修正されてなかったので、 http://rt.cpan.org/Ticket/Display.html?id=30033 に報告しときました。