1

I begginer in Perl and I've got this problem:

my $query = qq {select a1, count(b2), c3 from tab where d1 = ? group by a1, c3 };  
my $res = $dbh->selectall_hashref( $query,{ Slice => {} }, $id->[0]); 

When execute the code, I get:

DBI::st=HASH()->_prepare(...): attribute parameter  is not a hash at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/DBD/mysql.pm line 224.

Am I do something wrong?

Thanks for your attention.

jAbreu
  • 307
  • 2
  • 10

2 Answers2

3

I have the feeling you mean to be using selectall_arrayref. selectall_hashref takes an extra parameter (between the SQL and the attributes) specifying which field should be used as the hash key in the returned hash.

ysth
  • 96,171
  • 6
  • 121
  • 214
1

try

my $query = "select a1, count(b2), c3 from tab where d1 = ? group by a1, c3";
my $res = $dbh->prepare($query) or die("cannot prepeare");
$res->execute('10');
Programmer
  • 455
  • 5
  • 18
  • its not `$query->prepare($query)` its `my $res = $dbh->prepare($query)` then with `$res->execute()` enter the value to be entered – Programmer Feb 10 '14 at 13:16