List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:July 15 1999 4:36pm
Subject:Re: Am I doing this right?
View as plain text  
At 9:27 AM -0700 7/15/99, Jon Drukman wrote:
>At 03:29 AM 7/15/99 , Lincoln Yeoh wrote:
>>Perhaps one should do $cusor->fetchrow or die('error fetching row');
>>But so far MySQL hasn't died during fetchrow, well it hasn't died ;), so no
>>problems so far!
>i have found that the best thing to do is:
>my $dbh=DBI->connect(...)
>now whenever you do something that causes an error, your program
>automatically stops.  so you don't have to check every prepare, execute,
>fetch, etc. statement individually.

If the connect() call itself fails, though, $dbh is undef and the second
statement will be illegal.  You have to check for that case .  Or else you
can just turn on RaiseError in the connect() call itself:

my $dbh = DBI->connect($dsn,$user,$password, { RaiseError => 1});

Then DBI will exit on a failed connect and you don't have to check
the return value.

Paul DuBois, paul@stripped
Am I doing this right?Webmarquee Webmaster15 Jul
  • Re: Am I doing this right?Lincoln Yeoh15 Jul
    • Re: Am I doing this right?Jon Drukman15 Jul
      • Re: Am I doing this right?Paul DuBois15 Jul
  • Re: Am I doing this right?Douglas Brantz15 Jul
Re: Am I doing this right?Ryan Caveney15 Jul