Hi guys
I have the following fragment of code for connecting to a sybase database.
I need to detect whether or not the connection was successful.
 
$dbh =
DBI->connect("dbi:Sybase:server=$server;database=$db",$user,$password,
\%attr);
if (!$dbh) {
    print "Database Connection Unsuccessful...\n";
}
else {
    print "Database Connection Successful...\n";
}
 
OR
 
$dbh =
DBI->connect("dbi:Sybase:server=$server;database=$db",$user,$password,
\%attr);
if (!defined($dbh)) {
    print "Database Connection Unsuccessful...\n";
}
else {
    print "Database Connection Successful...\n";
}
 
The difference between them is the "defined" statement in the if statement
of the second code fragment.
Which is the better option ?
I assume the same applies for the DB disconnection ?
 
I would be most grateful if you could let me know
Many Thanks
Tony


Reply via email to