in reply to Re^2: DBI - selectcol_arrayref not working
in thread DBI - selectcol_arrayref not working
An alternative to Joost's solution is to set the RaiseError flag to true, causing DBI to throw an exception instead of retuning undef. However, avoiding RaiseError allows you to provide a more meaningful error message.
For example, the following dies with a meaninful error message on error. It also only reads one row since that's all you want.
my $ref = $dbh->selectcol_arrayref($query) or die("Unable to fetch blog name: ", $DBI::err || "Unknown database error", "\n"); $param{welcome} = $ref->[0];
Update: Added example.
|
|---|