On Thu, Mar 15, 2001 at 09:54:21AM -0500, Scott Phelps wrote:
> 
> Here's what doesn't work:
> 
> my $dbh=DBI->connect('dbi:ODBC:scottp', 'user', 'pass',
>               {RaiseError => 1,
>               AutoCommit => 1}
>               ) || errorhandler("Database connection error: $DBI::errstr");
> 
> $sth=$dbh->prepare("SELECT $content_field FROM $content_table WHERE page= ?
> AND type= ?");
> $sth->execute($content_page, $content_type);
> @content = $sth->fetchrow_array;
> $dbh->disconnect();
> 
> This of course returns an array (actually only one element) of the first row
> that satisfies my SQL statement.
> Is there a way to get the specific field of multiple rows that match my
> criteria into an array?

You can fetch all the rows at once, as a reference to an array of array
refs, one array ref per row.  Then, you can flatten the array of arrays
into a plain array.  This works best when you're selecting a single column
from the database.


my $rows = $sth->fetchall_array();
  # ref to array of array refs

@content = map @$_, @$rows;
  # flatten array refs into a single array


Ronald

Reply via email to