bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monasterians,

I'm completely puzzled by behavior I haven't experienced when using placeholders and bind values. It's a though I need to quote values or something. What am I missing after years of successful use?

my $stmt = q/SELECT * FROM users WHERE username= ? AND password = ?/; my @bind = ( $username, $password ); # doesn't work my @bind = ( 'wilma', 'foobar' ); # works my $acct = $dbh->selectrow_hashref($stmt, undef, @bind );

Update: I'm updating this because I don't want anyone who might be new to DBI to stumble across this node and be misled. Turns out, it had something, not sure what, with a dicey connection to our web server. Sounds crazy, but for an hour before a crash, the posted code didn't work with scalars, only hard-coded values. The server went down, and after the reboot, the code worked has it has for years. Sorry to waste previous PM bandwidth on an bizarre anomaly.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: Is there a need to escape bind values in DBI
by moritz (Cardinal) on Jan 15, 2008 at 20:32 UTC
    You don't need quotes in or for bind parameters.

    If one version fails and the other succeeds it has other reasons, for example one of the variables might not contain what you think it does.

Re: Is there a need to escape bind values in DBI
by runrig (Abbot) on Jan 15, 2008 at 19:39 UTC
    Is $username and $password set to something? If they're set correctly, there's no reason that what you're doing shouldn't work.
Re: Is there a need to escape bind values in DBI
by perrin (Chancellor) on Jan 15, 2008 at 20:13 UTC
    What error are you getting?

      I was not getting an error. And a Data Dump was showing positive values in my query. Please see the update in my OP.

      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot