in reply to DBI - selectcol_arrayref not working

$dbh->selectcol_arrayref returns undef when some errors occur. Have you checked $DBI::err?

Replies are listed 'Best First'.
Re^2: DBI - selectcol_arrayref not working
by PaulBerry (Novice) on Dec 20, 2006 at 19:55 UTC
    Sorry how do i check $DBI::err in this case? This is the entire snippet of code that I"m calling:
    use huff::WelcomeMessage; my $driver = MT::Entry->driver; my $dbh = $driver->{dbh}; my $query = "SELECT Name from NGBlogWelcome"; my $welcome = pop(@{$dbh->selectcol_arrayref($query)}); $param{welcome} = $welcome;

      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.