Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Don't ask to ask, just ask
 
PerlMonks  

Re^3: DBI and arrays

by tweetiepooh (Friar)
on Jan 17, 2012 at 13:27 UTC ( #948314=note: print w/ replies, xml ) Need Help??


in reply to Re^2: DBI and arrays
in thread DBI and arrays

There seems to be some confusion here about what you are passing. @bind_values needs to be an array of values not an array of hashes or other structure and the Slice is how the returned data is handled. Me thinks that your code needs to be more like

my @param = <array of values to pass TO database>; my $sql = <some SQL with placeholders = ? to take values>; my $array_ref = $dbh->selectall_arrayref($sql,undef,@param);
If you need to run the query for multiple sets of parameters you are better off preparing the SQL and then fetching the data multiple times with each set of parameters.
my $dbh = <create database handle>; my $sth = $dbh->prepare("select * from table where col1=? and col2=?") +; ... @param = ("test1a","test1b"); $array_ref = $sth->selectall_arrayref($sth,undef,@param); ... @param = ("test2a","test2b); $array_ref = $sth->selectall_arrayref($sth,undef,@param); ...
The use of statement handle in the selectall_arrayref is not something I've used yet but is in the DBI docs.


Comment on Re^3: DBI and arrays
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-04-20 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls