Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Passing a value into a WHERE clause

by dws (Chancellor)
on Jan 26, 2002 at 03:21 UTC ( [id://141686]=note: print w/replies, xml ) Need Help??


in reply to Passing a value into a WHERE clause

But how can you pass a variable into the first part of the WHERE clause?

Your example very nearly gets you there. The trick is to supply the field name before the DBMS sees the query. Easy enough to do. All you need is Perl's standard variable interpolation. Try something like:

my $field = 'answer'; my $value = 42; my $str = dbh->prepare("SELECT * FROM t WHERE $field = ?"); $sth->execute($value); ...

Replies are listed 'Best First'.
Re: Re: Passing a value into a WHERE clause
by peppiv (Curate) on Jan 28, 2002 at 18:58 UTC
    Unfortunately I have tried this approach to no avail. I have tried it with almost every variation of syntax I can think of. It seems that no matter what I do, if I put a string ($field) in the first part of the WHERE clause it returns 'unknown column' even though it's defined before the DBMS sees the query.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://141686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found