1

我想选择数据表单数据库并显示它们,但我遇到了以下问题:Can't call method "fetchrow_array" without a package or object reference

test.pl
我的 $q = new 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();

我无法弄清楚问题可能出在哪里。我是这门语言的新手,需要一些帮助

4

1 回答 1

0

execute返回 true/false 而不是语句处理程序,但看起来您正在将该返回值分配给$sqlSelect. 将 的返回值更改get_list$sqlSelect

  ...
  $sqlSelect->execute or die "can't execute the query: $sqlSelect->errstr";
  return $sqlSelect;
}

显示特定错误是因为$sqlSelect它是一个布尔值而不是对象引用(因此不能调用它的方法)。

于 2013-07-30T08:10:26.437 回答