in reply to Re: DBI - selectcol_arrayref not working
in thread DBI - selectcol_arrayref not working

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;

Replies are listed 'Best First'.
Re^3: DBI - selectcol_arrayref not working
by Joost (Canon) on Dec 20, 2006 at 20:00 UTC
Re^3: DBI - selectcol_arrayref not working
by ikegami (Patriarch) on Dec 20, 2006 at 20:15 UTC

    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.