Hi,
I have resolved the problem by adding a PrintError => 0 when creating the $dbh
object.
my $success = try {
$dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port", $user,
$passwd, {RaiseError=>1,PrintError=>0} )
or croak $DBI::errstr;
1;
} catch {
_write_log($_);
return undef;
}; if ($success) {
...
}
Thanks.
Tue, 20 May 2014 06:20:43 +0400 from Yonghua Peng <[email protected]>:
>Hello members,
>
>I wrote the code like below:
>
>try {
> $dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port",
>$user, $passwd) or croak $DBI::errstr;
>} catch {
> if ($_) {
> write_log($_);
> exit 1;
> }
>}; The problem is, when the connection fails, it write the error message to
>logs, but also print them to the terminal.
>
>So I add a statement and the code like below:
>
>try {
> local $SIG{'__WARN__'} = sub {};
> $dbh = DBI->connect("dbi:mysql:database=$db;host=$host;port=$port",
>$user, $passwd) or croak $DBI::errstr;
>} catch {
> if ($_) {
> write_log($_);
> exit 1;
> }
>}; Now everything seems work fine. The error message has been written to logs
>only, no output to the terminal.
>
>My question is , is it the correct way for doing this?
>
>Thanks in advance.
>