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

Re^3: DBI and arrays

by tweetiepooh (Hermit)
on Jan 17, 2012 at 13:27 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-28 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found