Rahul
Rahul

Reputation: 59

suppress stderr from perl DBI execute

my $sth = $dbh->prepare(q{
  INSERT INTO sales (product_code, qty, price) VALUES (?, ?, ?)
}) or die $dbh->errstr;
while (<>) {
    chomp;
    my ($product_code, $qty, $price) = split /,/;
    $sth->execute($product_code, $qty, $price) or die $dbh->errstr;
}
$dbh->commit or die $dbh->errstr;

I dont want to show stderr from $sth->execute on console. how to supress it ?

Upvotes: 1

Views: 282

Answers (1)

Dave Sherohman
Dave Sherohman

Reputation: 46187

This is controlled by the PrintWarn and PrintError settings for DBI handles. I generally turn them off globally when establishing the initial database connection ($dbh = DBI->connect($data_source, $user, $pass, { PrintWarn => 0, PrintError => 0 });) because I prefer to do my own error-handling and reporting, but it is also possible to set them on a per-statement level, turn them off for a single execute and back on afterward, etc. by using the set_err method.

Upvotes: 3

Related Questions