Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Creating Dynamic SQL statements using arrays

by MrCromeDome (Deacon)
on Jul 11, 2002 at 13:15 UTC ( [id://181013]=note: print w/replies, xml ) Need Help??


in reply to Creating Dynamic SQL statements using arrays

I posted a similar question to this once. . . Taking the great advice ehdonhon gave me, along with suggestions given above by blakem, Abigail-II, and Ryszard, you could come up with something like this:
push(@where_array, 'item1 = ?'); push(@params, $item1); push(@where_array, 'item2 = ?'); push(@params, $item2); push(@where_array, 'item3 = ?'); push(@params, $item3); my $select = join(', ',@select_array); my $where = join(' and ',@where_array); my $script = "SELECT $select FROM table WHERE $where"; . . . $sql->execute(@params);
This works the same way as the examples above, with the added benefit of placeholders. If the items in your where clause are coming from user input (especially a CGI), you'll definitely want to be using placeholders in your SQL statements.

Hope this helps,
MrCromeDome

Log In?
Username:
Password:

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

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

    No recent polls found