in reply to Populating an array via a DBI call - simplified

This is a great chance to bump one of the most classic nodes here: DBI recipes.

  • Comment on Re: Populating an array via a DBI call - simplified

Replies are listed 'Best First'.
Re^2: Populating an array via a DBI call - simplified
by edimusrex (Monk) on Mar 29, 2017 at 19:27 UTC

    Great thread. Seems the answer to my question is as followed ---

    my @accounts = @{$dbh->selectcol_arrayref("SELECT `UserName` FROM Acco +unt a, asscAccountAccountGroup aaag, asscRoleAccountGroup arag, Role +r WHERE a.Id = aaag.AccountId AND aaag.AccountGroupId = arag.AccountG +roupId AND arag.RoleId = r.Id AND r.Name = 'ROLE_REVIEWER'")}; print join("\n",@accounts);

    Thanks again for pointing me in the right direction

      If you don't really need the entire list of results in an array, you can just fetch one at a time like so:
      my $sth = $dbh->prepare($sql); $sth->execute(); $sth->bind_col( 1, \my $user_name ); while ( $sth->fetch() ) { print "$user_name\n"; }
Re^2: Populating an array via a DBI call - simplified
by edimusrex (Monk) on Mar 29, 2017 at 19:22 UTC
    Great! Thanks