in reply to Re: extract column data
in thread extract column data

i tried it but, i get cant locate object method fetchall_arrayref via package dbi::db

i always get this error when i try to use fetchall_arrayref

use DBI; my $host =""; my $db =""; my $usr =""; my $pwd =""; my $dbh = DBI->connect("DBI:mysql:$db:$host", $usr, $pwd, { AutoCommit => 0, RaiseError => 1, }) or die $DBI::errstr; my $sth = $dbh->fetchall_arrayref("SELECT lastname FROM dbase"); $dbh->disconnect; #its ok with array @data = $sth1; print @data;

Replies are listed 'Best First'.
Re^3: extract column data
by Corion (Patriarch) on May 24, 2017 at 12:22 UTC

    Maybe now is a good time to review DBI to see what methods can be called on which objects and what the sequence of when to call which is.

    If you are unable to modify your code to use ->fetchall_arrayref, consider reading the documentation for ->selectall_arrayref and using that method.

      selectall_arrayref seems to work but am getting

      ARRAY<0x1c56ba4>
      my $sth = $dbh->selectall_arrayref("SELECT lastname FROM dbase");

        Hello bigup401,

        The output is correct. See bellow:

        #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $array = ["Test1", "Test2"]; print $array . "\n"; print Dumper $array; __DATA__ $ perl test.pl ARRAY(0x83b178) $VAR1 = [ 'Test1', 'Test2' ];

        You can read a bit more at perlref.

        Hope this helps.

        Seeking for Perl wisdom...on the process of learning...not there...yet!