in reply to problem with fetchall_arrayref

having done this
my $sql_return = $sth->fetchall_arrayref({ Slice => {}}); print Dumper $sql_return;
I can see that the code doesn't do at all what I intended. How do i get each row as a hash_ref? I have to use a statement handler. I looked at fetchall_hashref and that requires that i define a key field and I don't want to.

many thanks

Replies are listed 'Best First'.
Re^2: problem with fetchall_arrayref
by oko1 (Deacon) on Dec 30, 2010 at 18:18 UTC

    If you don't want to define a key field, then you can't get the functionality you want. Come on, be reasonable. :)

    Note that $key_field can be an arrayref, a column number, or an arrayref containing a list of column numbers:

    #!/usr/bin/perl -w use strict; use DBI; use Data::Dumper; $|++; my $dbh = DBI->connect("dbi:mysql:wordpress","username","password"); my $sth = $dbh->prepare('SELECT ID, placeName FROM wp_ajax_places WHER +E ID <= 5'); $sth->execute; my $h = $sth->fetchall_hashref([ 1..2 ]); print Dumper(\$h);
    Output:
    $VAR1 = \{ '4' => { 'Akiachak AK' => { 'ID' => '4', 'placeName' => 'Akiachak AK' } }, '1' => { 'Ester AK' => { 'ID' => '1', 'placeName' => 'Ester AK' } }, '3' => { 'Akhiok AK' => { 'ID' => '3', 'placeName' => 'Akhiok AK' } }, '2' => { 'Aguikchuk AK' => { 'ID' => '2', 'placeName' => 'Aguikchuk AK' } }, '5' => { 'Akiak AK' => { 'ID' => '5', 'placeName' => 'Akiak AK' } } };
    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats