0
我继承了一些旧代码。它从MySQL数据库表中获取类别列表。我负责为他们添加多层次的支持。我已经完成了它,但由于某种原因,当我尝试应用程序时,它只是出错。为什么这个错误一直在发生?
错误的是(你也可以看到它在http://detyams.ru/?cat=1):
不能使用一个未定义的值作为/usr/local/lib/perl5/site_perl/mach/5.18/数组引用DBI.pm线2074,线2231
sub catlist
{
my $self=shift;
state $sth=$self->db->prepare(q/SELECT c.cat_id,c.cat_name,COUNT(pn.p_id) as cnt from category c
LEFT JOIN price_new pn ON (pn.cat_id=c.cat_id) GROUP BY pn.cat_id WHERE c.parent_id=?/);
$sth->execute(0);
my @catlist=$sth->fetchall_arrayref({}); # <- this call leads to the failure in the deep of DBI code.
foreach my $item (@catlist)
{
$sth->execute($item->{cat_id});
$item->{children}=$sth->fetchall_arrayref({});
}
return @catlist;
}
我抬起头来使用DBI方法的一些具体的例子在那里(如http://www.perlmonks.org/?node_id=284436#loh),似乎都与我的代码一致。
这些downvotes是什么? – ZzZombo