使用:
的MySQL 5.5 的activeperl v5.14.1 64位Windows 7
下面的脚本有一个未定义的$ DBI: :在执行调用失败errstr:
#!c:/perl/bin/perl.exe -w
use DBI;
my $dbh = DBI->connect('dbi:mysql:cq','root','password') or die "Connection Error: $DBI::errstr\n";
# This SQL should fail because of a foreign key constraint
my $sql = "delete from Player where ID=6462";
my $sth = $dbh->prepare($sql);
$sth->execute or die "SQL Error: $DBI::errstr\n";
当脚本运行的输出是:
Use of uninitialized value $DBI::errstr in concatenation (.) or string at testmysql2.pl line 10.
SQL Error:
通过HeidiSQL的SQL运行提供了预期的外键错误: (我不能插入图像,因为我是一个新用户)
在Windows XP 32位运行相同的脚本提供了预期的错误:
DBD::mysql::st execute failed: Cannot delete or update a parent row: a foreign key constraint fails (`cq`.`messageboard`, CONSTRAINT `messageboard_ibfk_1` FOREIGN KEY (`PlayerID`) REFERENCES `player` (`ID`)) at testmysql2.pl line 10.
SQL Error2: Cannot delete or update a parent row: a foreign key constraint fails (`cq`.`messageboard`, CONSTRAINT `messageboard_ibfk_1` FOREIGN KEY (`PlayerID`) REFERENCES `player` (`ID`))
注:无论SQL的
出现该问题,例如SQL语法错误也将导致一个未定义的$ DBI :: errstr
有趣的是共同返回nnection错误 - 例如,停止MySQL服务 - 运行脚本和下面的输出给定,如预期:
DBI connect('cq','root',...) failed: Can't connect to MySQL server on 'localhost' (10061) at testmysql2.pl line 4
Connection Error: Can't connect to MySQL server on 'localhost' (10061)
设置跟踪级别没有提供有用的信息(对我来说):
$sth->trace(5, "trace.txt");
$sth->execute or die "SQL Error: $DBI::errstr\n";
与trace.txt的一些重新格式化为一个片段:
dbd_st_free_result_sets
mysql_st_internal_execute MYSQL_VERSION_ID 50147
parse_params statement delete from Player where ID=6462
dbd_st_execute returning imp_sth->row_num 18446744073709551614
execute= (undef) [1 items] at testmysql2.pl line 11
DESTROY for DBD::mysql::st (DBI::st=HASH(0x29dc0a8)~INNER) thr#2a97e8
正确的SQL操作为预期。我猜这是Windows 7 64位的错误? - 但我不清楚/失去了如何解决或找到正确的地方报告/找出明确。
如果你有这么远......感谢阅读!
什么版本的'DBI'和'DBD :: mysql'? – mob