in reply to Re^2: DBI and arrays
in thread DBI and arrays
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 @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);
The use of statement handle in the selectall_arrayref is not something I've used yet but is in the DBI docs.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); ...
|
|---|