Try $hostnames = $dbh->selectcol_arrayref("SELECT hostname FROM tblHost WHERE
status="started";)
Tim.
On Mon, Oct 07, 2002 at 11:58:07AM -0400, Janek Schleicher wrote:
> Chad Kellerman wrote:
>
> >Hi everyone,
> >
> > I thought $sth->fetchrow_array would do the trick but its not. I am
> >using mysql on linux and I have a query:
> >
> >SELECT hostname FROM tblHost WHERE status="started";
> >
> >which returns a list of hostnames. I though the fetchrow_array would
> >return a array of hostnames but it does not seem to. It seems to only
> >return the first hostname unless I put it in a while loop.
> >
> > Is there a way that I can grab every hostname from the table into an
> >array so that I can run soemthing like a foreach on it??
>
> If you can live with a little speed penalty,
> you can use the DBIx::Simple module from CPAN.
>
> use DBIx::Simple;
> my $db = DBIx::Simple->connect('DBI:mysql:$db', $user, $passwd)
> or die "Cannot connect to database: $!";
> my @hostname = $db->query(
> qq{SELECT hostname FROM tblHost WHERE status = ?},
> 'started'
> )->flat;
> foreach (@hostname) {
> # ...
> }
>
>
> Greetings,
> Janek
>