in reply to Can't call on undefined value (DBI) + constructive feedback asked.

$dbh = DBI->connect($datasource, $username, $password, {RaiseError => +1}) or die $DBI::errstr;

RaiseError doesn't affect the actual connect() call, just any method called on the $dbh afterwards.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

  • Comment on Re: Can't call on undefined value (DBI) + constructive feedback asked.
  • Download Code

Replies are listed 'Best First'.
Re^2: Can't call on undefined value (DBI) + constructive feedback asked.
by mifflin (Curate) on Aug 03, 2004 at 15:27 UTC
    Are you sure? In my experience this code will not call my die statement because RaiseError is on....
    use DBI; eval { # this connect will fail $dbh = DBI->connect('dbi:Oracle:dev', 'user', 'pass', {RaiseError = +> 1, PrintError => 0}) || die "my die"; print "after connect\n"; }; if ($@) { print "$@\n"; }
    The output when running this code is...
    # perl test.pl DBI connect('dev','user',...) failed: ORA-01017: invalid username/pass +word; logon denied (DBD: login failed) at test.pl line 5
    But this code will call the die statement because RaiseError is off...
    use DBI; eval { # this connect will fail $dbh = DBI->connect('dbi:Oracle:dev', 'user', 'pass', {RaiseError = +> 0, PrintError => 0}) || die "my die"; print "after connect\n"; }; if ($@) { print "$@\n"; }
    This output when running this code is...
    # perl test.pl my die at test.pl line 5.
    Update: The DBI Changes file says this
     Changes in DBI 0.91,	10th December 1997
      ...
      DBI->connect(..., { RaiseError=>1 }) now croaks if connect fails.
      ...