On Thu, May 06, 2004 at 09:53:42AM -0700, Arzola, Nelson wrote:
> I've read the DBI documentation and I've searched the DBI-users archive. I
> found the selectrow_arrayref and selectrow_hashref commands to be almost exactly
> what I'm looking for. The issue is that I would like to bind a sql data type to one
> or more of the placeholders. At the moment, I'm using something that looks like
> this:
>
> $SQL = qq{SELECT col1, col2, col3 FROM mytable WHERE col1=? AND col2=?};
>
> $sth = $dbh->prepare_cached($SQL);
> $sth->bind_param(1, $col1_val, SQL_INTEGER);
> $sth->bind_param(2, $col2_val, SQL_VARCHAR);
> $data = $dbh->selectall_arrayref($sth);
>
>
> Looking at the documentation for selectrow_arrayref and selectrow_hashref, it
> seems that I could provide the data types and the binding in one call. The problem
> is that I can't find anything in the documentation for how to format and what to put
> in the %attr value. I would like to write my DBI calls like this:
> %attr = (??????); # don't know what to put here
> $data = $dbh->selectall_arrayref($sth, \%attr, $col1_val1, $col2_val);
The bind_param's have to be done explicitly. As per your first example.
Tim.