gpt4 book ai didi

mysql - Perl DBD fetchrow_array 错误 :

转载 作者:行者123 更新时间:2023-11-29 06:42:27 27 4
gpt4 key购买 nike

我在读取 MySQL 时遇到了一些奇怪的错误,我的代码是这样的:

my $sql = <<"sqleof";
select t1.name t1_name, t2.name t2_name from t2
inner join t1 using(Id)
where t2.Id in (select Id from t3 where t3Id='$id')
sqleof
#here $dbh had connected correctly and done some query before this; $sql can execute pretty well on MySQL command line and return me some records.
my $execute = $dbh->prepare($sql);
$execute->execute or die "Error: $DBI::errstr\n";
my @client = $execute->fetchrow_array() or die "Error: $DBI::errstr\n";
#here I got error saying: DBD::ODBC::st fetchrow_array failed: Unable to fetch information about the error

有什么问题?

大家好,打扰了。我找到了原因。这是一个低级别的错误,因为我使用了多个 $dbh 并且我弄错了执行名称。

    my $execute_A = $dbh->prepare($sql);
$execute_A->execute or die "Error: $DBI::errstr\n";
my @client = $execute_B->fetchrow_array() #$execute_B here when I copied lines and modified.

您的帮助对我来说非常重要。谢谢大家。

最佳答案

替换

my @client = $execute->fetchrow_array() or die "Error: $DBI::errstr\n";

my @client = $execute->fetchrow_array();

你正在获取空数组,这不适合作为 ..or die .. 建议的错误检查。

.. or die .. 仅对 prepareexecute 方法有意义。


旁注,您还缺乏适当的错误检查:

my $execute = $dbh->prepare($sql) or die $dbh->errstr; # not $DBI::errstr
$execute->execute or die $execute->errstr; # not $DBI::errstr

另外,使用sql占位符来防止sql injection .

关于mysql - Perl DBD fetchrow_array 错误 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20664164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com