in reply to perl, mysql: "fetchrow_array failed: fetch() without execute()"
If it's the same problem as the other thread, proper use of my will fix it. Don't you use use strict; use warnings;?
my $ID = ...; my $query = ...; my $sth = $dbh -> prepare($query); $sth -> execute; my @row = $sth -> fetchrow_array;
Another possibility is that there was an error performing the execute. Since you don't check for errors, did you specify RaiseError => 1?
Two other comments:
my $i = 0; for my $item (@{$clusters}) { ... $i++ }
can be written more simply as
for my $i (0..$#$clusters) { ... }
This one is a serious problem. Just adding quotes around the contents of $ID doesn't properly convert it from arbitrary text into an SQL string literal. You need one of the following, preferably the second:
for my $i (0..$#$clusters) { my $ID = $units[$i][0]; my $query = "select * from finalLevel3 where id=" . $dbh->quote($I +D); my $sth = $dbh -> prepare($query); $sth -> execute; my @row = $sth -> fetchrow_array; ... }
my $query = "select * from finalLevel3 where id=?"; my $sth = $dbh -> prepare($query); for my $i (0..$#$clusters) { $sth -> execute( $units[$i][0] ) my @row = $sth -> fetchrow_array; ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl, mysql: "fetchrow_array failed: fetch() without execute()"
by Marshall (Canon) on Dec 29, 2008 at 09:57 UTC | |
by ikegami (Patriarch) on Dec 29, 2008 at 10:18 UTC | |
by Marshall (Canon) on Dec 29, 2008 at 13:46 UTC | |
by DStaal (Chaplain) on Dec 29, 2008 at 14:26 UTC | |
by runrig (Abbot) on Dec 29, 2008 at 17:01 UTC |