Hello,

I'm using the Perl DBI to access a MySQL database.

I'm trying to fetch all rows in a integer column.  When I manually interact 
with MySQL, I get all of the values, whether they're zero or not. But when I 
use DBI to do it, it seems to throw out any zero values. e.g.

(apologies for the formatting)

The query in the mysql interface:
mysql> select grade from student_assignment;
+-------+
| grade |
+-------+
|    22 |
|    20 |
|    20 |
|    22 |
|    25 |
|    15 |
|     0 |
|    17 |
|    16 |

--snip--


The query in perl dbi:

--snip--
my $assignment_query =
  "SELECT grade " .
  "FROM student_assignment";
my $sth = $dbh->prepare($assignment_query);
$sth->execute();
my @assignments;
while ( my $grade = $sth->fetchrow() )
{
  push(@grades,$grade);
}
print "@grades";
--snip--

This generates an array containing
22 20 20 22 25 15 17 16

The 0 value is missing.

Is there any way to have zero values not thrown away?

(Please excuse any oddities in my perl coding technique, I have not been at 
this long...)

Thanks,

Peter

Reply via email to