PDA

View Full Version : Fetch single value using dbi


tom123
08-16-2006, 12:44 PM
Hi guys

Is there any quick way of retreiving a value from dbi, if you know you will only have a single value returned i.e. 122

At the moment i do


my $product_ref = $sth->fetchall_arrayref();
foreach my $row (@$product_ref)
{
foreach my $field (@$row)
{
push (@product, $field);
}
}

Thanks in advance

FishMonger
08-16-2006, 05:30 PM
I'd need to to have a better idea of the context, i.e. is @product already defined with values, and are you retrieving a single row with multiple columns or multiple rows with only 1 column.

Depending on the context, one of these should work.

@product = $dbh->selectrow_array($statement);

push @product, $dbh->selectrow_array($statement);

push @product, [$dbh->selectrow_array($statement)];