On 09/04/2012 14:24, Vyacheslav wrote:
My code
my %attr = (
PrintError => 0,
RaiseError => 0
);
my $dbh = DBI->connect($dsn, $user, $pass, \%attr);
unless ($dbh) {
next;
}
my $query = "SHOW DATABASES";
I use
unless ($dbh) {
next;
} and this work fine.
Thanks
09.04.2012 01:22, Jim Gibson написал:
At 12:50 AM +0000 4/9/12, Vyacheslav wrote:
I enabled RaiserError, then script die.
...
my %attr = (
PrintError => 0,
RaiseError => 1
);
Use:
RaiseError => 0
instead so that your script will not raise an exception and die. Then
check $dbh->err.
Hi Vyacheslav
I suggest you use this instead
my $dbh = DBI->connect($dsn, $user, $pass) or do {
warn "Can't connect to database $db: $DBI::errstr\n";
next;
};
so that your program shows which database connections have failed and
been skipped.
This is pretty much the same as your original code except that a failure
to connect causes a warning instead of a fatal 'die', and execution
skips to the next database source. Also the warning string shows the
name of the database instead of saying just "Can't connect to the DB".
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/