Philip, thank you very much. I overlooked the meaning of the second variable to 
selectrow_array entirely.

Two follow up questions:
1. If I don't need or want DBI handle attributes (I'm happy with the defaults, 
for instance), how can I define a null hash reference?
2. I chose selectrow_array specifically because I didn't need the 
prepare/execute/fetch routine. The query result is either a) the author is 
already in the table, and I want the record id number, or b) the author isn't 
in the table, and I'm going to add the name and then find the record id number 
of the record just added. There should never be more than one matching author 
name in the table, so I didn't think I needed a fetch capable of multiple rows. 
You're suggesting I look at fetchrow_array(). Am I overlooking something that 
you're aware of?

Thanks, again, for your help.

-Kevin

>>> "Philip M. Gollucci" <[EMAIL PROTECTED]> 05/05/05 03:38PM >>>
KEVIN ZEMBOWER wrote:

>I'm using a function from DBI that needs a hash reference according to the 
>documentation, and I don't know how to turn $_ into one. The section of code I 
>have is:
>   if ($record{"Author"}) {
>      my @indfields = split(/\|/, $record{"Author"});
>      foreach (@indfields) {
>         my $authorid = $dbh->selectrow_array("SELECT authorid FROM author 
> WHERE name = ?", $_)
>            or die "Can't execute statement: $DBI::errstr";
>
>
>  
>
perldoc DBI

The second argument to this is a hashref of DBI handle attributes not 
the bind values

you want:

$dbh->selectrow_array($sql, \%db_attrs, ($_));

somewhere above:
our %db_attrs = (
    RaiseError => 1,
    PrintError => 0,
    AutoCommit => 1,
    Taint      => 1
    ......
);

Also, the how point of using bind values is you should $dbh->prepare() 
your query outside of the loop.

then $sth->execute($_) in the loop.

and $sth->finish() after the loop.

Check out $sth->fetchrow_arrary() instead.

HTH

-- 
END
-----------------------------------------------------------------------------
Philip M. Gollucci
Senior Developer - Liquidity Services Inc.
Phone:  202.558.6268 (Direct)
E-Mail: [EMAIL PROTECTED] 
Web:    http://www.liquidation.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to