为什么这个错误不断发生?

Why this error keeps occurring?

我继承了一些旧代码。它从 MySQL 数据库 table 中获取类别列表。我的任务是为他们增加多层次的支持。我几乎完成了它,但出于某种原因,当我尝试运行该应用程序时它只是出错了。

错误是(你也可以在http://detyams.ru/?cat=1看到):

Can't use an undefined value as an ARRAY reference at /usr/local/lib/perl5/site_perl/mach/5.18/DBI.pm line 2074, line 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),所有这些似乎都符合我的代码。

哦,所以,如果出现查询语法错误(WHERE 子句放置在错误的位置),fetchall_arrayref() 似乎报告神秘错误而不是根本问题。通过检查服务器日志发现。