Title: Capture the connect exception (MySQL)

Hi all,
The following snip works fine for me, BUT
1. I'm concerning, is that the right way to catch the 'connect' exception/s?
2. Are there other manners to do it?


use strict;
use DBI;
my ($hostname, $database, $username, $password, $port) = … <legal param-s>

# ---------------------------------------------------------------------------------------------
    my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
    eval {
        $DBH = DBI->connect($dsn, $username, $password, { RaiseError => 1, });
    };
    $DBH ? print("Got it!") : print("Failed!"), print $@ if $@;
# ---------------------------------------------------------------------------------------------



Thank's.

Reply via email to