Gossamer Forum
Home : General : Databases and SQL :

no output using fetchrow_array()

Quote Reply
no output using fetchrow_array()
I am not getting any output using the below code.

#!/usr/bin/perl

use strict;
use warnings;
use DBI;
--
connecting to database (okay with this, it works)

--
my (@centers, $stmt, $sth, $row);
$stmt = qq { SELECT group_center FROM places};
$sth = $dbh->prepare($stmt);
$sth->execute();

#here is the problem area
while ($row = $sth->fetchrow_array()) {
push @centers, $_;
}
foreach (@centers) {
print "$_\n";
}
I get a blank line for each line, where I would expect to see names of groups from my query. ???





Quote Reply
Re: [narsil] no output using fetchrow_array() In reply to
Because you are assigning the return value from fetchrow_array to $row and then you are pushing the empty $_ into the array.

If you are just printing it out you may as well put the print statement inside the while loop rather than doing a while and foreach loop.
Quote Reply
Re: [Paul] no output using fetchrow_array() In reply to
yep, thanks. I was printing it out just to test the output.

it turns out that I should have just been pushing the
$row scalar onto the array, instead of the $_,

thanks for the reply