I enabled RaiserError, then script die.
...
my %attr = (
PrintError => 0,
RaiseError => 1
);
my $dbh = DBI->connect($dsn, $user, $pass, \%attr); # or die "Can't
connect to the DB: $DBI::errstr\n";
my $query = "SHOW DATABASES";
my $sth = $dbh->prepare($query) or die "Can't prepare SQL statement:
$DBI::errstr\n";;
$sth->execute;
my @dbs;
while ( my $data = $sth->fetchrow_arrayref ) {
push @dbs, $data->[0];
}
...
DBI connect('information_schema:db1:3306','test',...) failed: Can't
connect to MySQL server on 'db1' (111) at ./dbcheck.pl line 72
I test with $dbh->err, but the script all the same die.
08.04.2012 18:40, Dr.Ruud пишет:
On 2012-04-08 17:10, Vyacheslav wrote:
using eval helped me.
You should not use exceptions for normal code flow.
Read the DBI docs (perldoc DBI).
If a failed connection must be an exception, set RaiseError to true.
But if it isn't an exception, leave it false, and test $dbh->err (or
the global $DBI::err).
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/