Ho, Tony [[EMAIL PROTECTED]] wrote:
> 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";
> }

Another way described in 'perldoc DBI' is

   $dbh = DBI->connect($data_source, $username, $password)
                          or die $DBI::errstr;

Also, read the DBI perldocs on RaiseError and exception
handling with "eval".  If you're not, you should be error
checking *all* your dbi statements - not just your connect.

HTH.

-- 
Hardy Merrill
Senior Software Engineer
Red Hat, Inc.

Reply via email to