
kwatts59
Novice
Jun 23, 2017, 1:08 PM
Post #1 of 8
(24757 views)
|
Problem with fetchrow_array
|
Can't Post
|
|
Hello all, I am having problems with fetchrow_array. It prints all the gene symbols and runs fine until the last record, then it fails. Below is the code:
$sql_cmd = "select gene_symbol,refseq_id from gene_symbols where gene_symbol is not null"; my $sqlquery = $dbh->prepare($sql_cmd) or die "Cannot prepare query \n"; my $rv1 = $sqlquery->execute or die "Cannot execute query $sql_cmd\n"; my @row = $sqlquery->fetchrow_array or die "Cannot fetch $sql_cmd\n"; my $i = 0; while (defined $row[0]) { $i++; $gene_symbols[$i] = $row[0]; print "$i\t$row[0]\n"; @row = $sqlquery->fetchrow_array or die "Cannot fetch $sql_cmd\n"; } print "Loaded $i gene symbols\n"; $TOTAL_GENES= $i; When it gets to the last row in the query, it just fails with "Cannot fetch select gene_symbol,refseq_id from gene_symbols where gene_symbol is not null" It doesn't exit the loop and it doesn't get to the print command "Loaded xxx gene symbols" at the end of the while loop. Any help would be appreciated. Thanks in advance. Ken
(This post was edited by kwatts59 on Jun 23, 2017, 1:10 PM)
|