我想选择数据表单数据库并显示它们,但我遇到以下问题:Can't call method "fetchrow_array" without a package or object reference
test.pl
我的$ q =新CGI();
my $handle = Db::connection();
sub select{
my $rData = {
table => 'student',
condition => {
ID => 100,
}
};
return Db::select($rData);
};
print $q->header;
print $q->start_html(
-title => "Main",
-style => {-src =>'/media/css/start/jquery-ui-1.10.3.custom.css" rel="stylesheet' },
-script => [
{ -src=>'/media/js/jquery-1.9.1.js'},
{ -src=>'/media/js/jquery-ui-1.10.3.custom.js'},
{ -src=>'/media/js/jquery.dataTables.js'},
]
);
my $cScript = qq{
\$(document).ready(function(){
oTable = \$('#id_table').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
});
\$("input[type=button], a, button")
.button()
.click(function( event ){
event.preventDefault();
});
});
};
print $q->script($cScript);
print start_form (-method => 'post', -action => "" );
my @aRows;
my $sqlSelect = Dbm::get_list({
table => 'personi',
condition => {
ID => 100,
}
});
while (my @data = $sqlSelect->fetchrow_array()) {
my $cRowId = hidden('rowid', $data[0]);
my $bt1 = image_button({-src => '/media/images/delete_1.png',
-class => 'del',
-title => 'delete',
-name => 'delete',
-value => $data[0],
my $bt2 = image_button({-src => '/media/images/edit_1.png',-class => 'upd', -title => 'update', -name => 'update', -value => $data[0]});
push @aRows, ($cRowId, $q->Tr($q->td([$data[1], $data[2], $data[3], $bt1, $bt2])));
}
print $q->table({-border => '1px solid green',-align =>'center', -width => '100%', -id => 'id_table'},
thead($q->th(['Name', 'Surname', 'Age', 'Delete', 'Edit'])),
@aRows,
);
print $q->input({-type => 'button', -class => 'button', -onclick => "window.location.href='insert.pl';", -value => 'Shto'});
print $q->end_form;
print test_select();
我无法弄清楚问题出在哪里。我是这门语言的新手,需要一些帮助
答案 0 :(得分:0)
execute
返回true / false而不是语句处理程序,但看起来您将该返回值赋给$sqlSelect
。将get_list
的返回值更改为$sqlSelect
。
...
$sqlSelect->execute or die "can't execute the query: $sqlSelect->errstr";
return $sqlSelect;
}
正在显示特定错误,因为$sqlSelect
因此是布尔值而不是对象引用(因此不能在其上调用方法)。