自2011年以来一直处理此问题。通常能够解决此问题。现在出现了这样一种情况:我真的需要能够处理错误,而且我在想,人们多年以来就知道这个问题,看起来像是修复列表上的高级事物,但最新的DBI升级问题仍未解决。有没有人找到解决办法,或知道如何破解库,并获取DBI :: errstr携带值时出现错误?Win 64草莓Perl DBI没有错误报告错误仍然没有解决?
这里是我的代码(是我知道的问题瓦特/空的root密码):现在
use strict;
use DBI;
use DBD::mysql;
use Data::Dumper;
my $platform = "mysql";
my $database = "test";
my $host = "localhost";
my $port = "3306";
my $user = "root";
my $pw = "";
my $dsn;
$dsn = "dbi:mysql:$database:$host:$port";
my $DBI_connect = DBI->connect($dsn, $user, $pw, {RaiseError => 1,PrintError=>1}) or die "$DBI::errstr\n";
my $sql_str = 'INSERT INTO test_tablexx (\'xxx) VALUES (blah)';
my $DBI_query_handle = $DBI_connect->prepare($sql_str) or die "Can't prepare SQL statement: $DBI::errstr\n";
my $return = $DBI_query_handle->execute() or warn "$DBI::errstr\n";
print "sys arry".Dumper [email protected]"\n";
print "err: ".$DBI_query_handle->err."\n";
print "errstr: ".$DBI_query_handle->errstr."\n";
print "state: ".$DBI_query_handle->state."\n";
print "err: ".$DBI_connect->err."\n";
print "errstr: ".$DBI_connect->errstr."\n";
print "state: ".$DBI_connect->state."\n";
print Dumper $DBI_query_handle;
print "\n\n-------------------------------------------------------------------\n\n";
my $hash = DBI->installed_versions;
print Dumper $hash;
,该表是无效的,列有在它和中间报价值是一个未加引号的字符串。应该像圣诞树一样点亮错误处理。
如果我将执行语句更改为“$ DBI :: errstr \ n”,它会出错:它会死亡,但根本没有消息。
然而,这里是结果:
sys arry$VAR1 = '
';
err:
errstr:
state:
err:
errstr:
state:
$VAR1 = bless({}, 'DBI::st');
-------------------------------------------------------------------
$VAR1 = {
'DBD::SQLite' => '1.37',
'DBD::ExampleP' => '12.014311',
'DBD::Sponge' => '12.010003',
'DBD::Pg' => bless({
'original' => '2.19.3',
'qv' => 1,
'version' => [
2,
19,
3
]
}, 'version'),
'DBD::Gofer' => '0.015327',
'DBD::DBM' => '0.08',
'DBD::mysql' => '4.022',
'DBD::ADO' => '2.99',
'DBD::ODBC' => '1.41',
'DBI' => '1.631',
'DBD::File' => '0.42'
};
的最后一位是版本信息转储,所以你们可以看到我最新的与我的DBI安装。
现在,当我改变数据库的东西不存在,例如:我的$ database =“的testXXX”,它确实火了一个错误:
DBI connect('testxx:localhost:3306','root',...) failed: Unknown database 'testxx' at ../sql_tester.pl line 17.
的信息的最后一位为你当我倾倒$ DBI :: lasth,我可以看到错误的方法是联合国民主基金:
print Dumper $DBI::lasth;
$VAR1 = bless({
'FetchHashKeyName' => 'NAME',
'TraceLevel' => 0,
'ImplementorClass' => 'DBD::mysql::db',
'dbi_imp_data' => undef,
'State' => \undef,
'Username' => 'root',
'Errstr' => \undef,
'ChildHandles' => [
bless({}, 'DBI::st')
],
'Driver' => bless({
'Attribution' => 'DBD::mysql by Patrick Galbraith',
'FetchHashKeyName' => 'NAME',
'TraceLevel' => 0,
'ImplementorClass' => 'DBD::mysql::dr',
'State' => \undef,
'Version' => '4.022',
'Errstr' => \undef,
'ChildHandles' => [
bless({}, 'DBI::db')
],
'Name' => 'mysql',
'Err' => \undef
}, 'DBI::dr'),
'Statement' => 'INSERT INTO test_tablexx (\'xxx) VALUES (blah)',
'Name' => 'test:localhost:3306',
'dbi_connect_closure' => sub { "DUMMY" },
'Err' => \undef
}, 'DBI::db');
所以请请的这么好的人,我该怎么办时,编程的最重要的原则之一 - 错误处理 - 在我的程序的核心模块中不起作用?!
模块的作者在报告错误时说了些什么? – ikegami