in reply to Re: Not an ARRAY reference Error Help!
in thread Not an ARRAY reference Error Help!

Hi, adding this is not a problem: my $sth = $dbh->prepare($sql) or die $dbh->errstr; The issue is with the rest of the code, I just don't understand how I can make this work.

Replies are listed 'Best First'.
Re^3: Not an ARRAY reference Error Help!
by Limbic~Region (Chancellor) on Jan 13, 2011 at 19:49 UTC
    Anonymous Monk,
    You misunderstand. I pointed out a problem you didn't know you had because you haven't encountered it yet. I also pointed out what your problem was - you are treating a hash reference as an array reference. Instead of just changing things without understanding hoping it will work, try starting with the most basic working code you can (connecting to the DB) and then add things 1 piece at a time. That way, when something breaks you will know it is the last thing you added. You have many more problems with that code then you think you do as it is.

    Cheers - L~R

Re^3: Not an ARRAY reference Error Help!
by derby (Abbot) on Jan 13, 2011 at 19:47 UTC

    my $dbh = database->connect_mysql(); my $sql = "select * FROM mytable WHERE date < DATE_ADD(NOW(), INTERVAL -30 DAY)"; my $records = $dbh->selectall_arrayref( $sql, { Slice => {} } ); foreach my $record ( @$records ) { my $user = $record->{user}; my $id = $record->{id}; print "Data Test: $user - $id<br>"; }
    Check out the 'You may often want to fetch an array of rows where each row is stored as a hash' section of the DBI documentation.

    -derby