我想知道为什么在连接到任何数据库时会出现警告。DBI_TRACE=1
奖励指出了一种编写不展示它的干净代码的方法。
我说的!! warn: 0 CLEARED by call to connect method
是似乎无害的,因为代码确实按预期工作。请注意,如果不设置 DBI 跟踪模式,它不会出现。
示例 Perl 代码(使用 SQLite):
use warnings;
use DBI;
DBI->connect("dbi:SQLite:dbname=test.sqlite","","") or die $DBI::errstr;
样本输出:
DBI 1.612-ithread default trace level set to 0x0/1 (pid 12814 pi 1ddd010) at DBI.pm line 275 via test.pl line 2
-> DBI->connect(dbi:SQLite:dbname=test.sqlite, , ****)
-> DBI->install_driver(SQLite) for linux perl=5.010001 pid=12814 ruid=1000 euid=1000
install_driver: DBD::SQLite version 1.29 loaded from /usr/lib/perl5/DBD/SQLite.pm
<- install_driver= DBI::dr=HASH(0x204da38)
!! warn: 0 CLEARED by call to connect method
<- connect('dbname=test.sqlite', '', ...)= DBI::db=HASH(0x204e278) at DBI.pm line 662
<- STORE('PrintError', 1)= 1 at DBI.pm line 714
<- STORE('AutoCommit', 1)= 1 at DBI.pm line 714
<- STORE('PrintWarn', 0)= 1 at DBI.pm line 717
<- FETCH('PrintWarn')= '' at DBI.pm line 717
<- STORE('Warn', 0)= 1 at DBI.pm line 717
<- FETCH('Warn')= '' at DBI.pm line 717
<- STORE('Username', '')= 1 at DBI.pm line 717
<> FETCH('Username')= '' ('Username' from cache) at DBI.pm line 717
<- connected('dbi:SQLite:dbname=test.sqlite', '', ...)= undef at DBI.pm line 723
<- connect= DBI::db=HASH(0x204e278)
<- STORE('dbi_connect_closure', CODE(0x204da08))= 1 at DBI.pm line 732
<- DESTROY(DBI::db=HASH(204e1d0))= undef
<- disconnect_all= '' at DBI.pm line 740
! <- DESTROY(DBI::dr=HASH(204da38))= undef during global destruction