[英]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;
我不想在控制台上顯示來自 $sth->execute 的 stderr。 如何壓制它?
這由 DBI 句柄的PrintWarn和PrintError設置控制。 我通常在建立初始數據庫連接時全局關閉它們( $dbh = DBI->connect($data_source, $user, $pass, { PrintWarn => 0, PrintError => 0 });
)因為我更喜歡這樣做自己的錯誤處理和報告,但也可以通過使用set_err方法將它們設置在每個語句級別,將它們關閉以進行單次execute
並在之后重新打開等等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.