Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to interpolate sql-output

by graff (Chancellor)
on Jan 14, 2015 at 03:09 UTC ( [id://1113172]=note: print w/replies, xml ) Need Help??


in reply to How to interpolate sql-output

I'm pretty sure I don't understand what you're asking. In general, the best way to "interpolate" values into an sql query is by using placeholders with DBI.

If you want this literal string of eight characters - $in{cid} - to be the value being tested in the where clause, you could do it like this:

my $dbh = DBI->connect( $whatever… ) ... my $sth = $dbh->prepare( "select field from table where id != ?" ); $sth->execute( '$in{cid}' ); # an 8-character string is the placehold +er value ...
On the other hand, if $in{cid} is an actual hash element in your script, and it happens to contain a string or number that you want to use as the value to be tested in the where clause, then:
my %in; $in{cid} = "something"; my $dbh = DBI->connect( $whatever… ) ... my $sth = $dbh->prepare( "select field from table where id != ?" ); $sth->execute( $in{cid} ); # the hash element value is the placeholde +r value ...
Did you have something in mind other than these two cases?

Sorry - I'll try to respond again, now that I understand the question.

Replies are listed 'Best First'.
Re^2: How to interpolate sql-output
by Seq (Novice) on Jan 14, 2015 at 03:36 UTC

    No worries. I just hoping to find something like this:
    $sql=${"$per->{value}"} or something...

Log In?
Username:
Password:

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

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

    No recent polls found