in reply to Re: perl, mysql: "fetchrow_array failed: fetch() without execute()"
in thread perl, mysql: "fetchrow_array failed: fetch() without execute()"
$query = "select * from finalLevel3 where id=\"$ID\";"; $sth = $dbh -> prepare($query); # I would suggest this: my $query = $dbh->prepare("SELECT * FROM finalLevel3 WHERE id='$ID'");
I personally like to captialize the SQL key words, but preferences vary. Also the single quote within the double quote will expand $ID just fine. There is no need for \" in this situation. I was amazed when I learned this.
I am also a bit confused about this:
foreach $item (@{$clusters}) { #..... }
I would think that since you are iterating over clusters, that something like this would be more clear:
So when do you need the extra {}? You need this when dereferencing an indexed expression, but not a non-indexed one. You also need the extra {} to make a list from a list ref returning function.foreach my $cluster (@$clusters) { #..... }
my @list = @{listRefReturningFunction()}; #also consider: my $r = {"a" => [1,2,3,4], "b" => [5,6,7,8], }; print @{$r->{"a"}}; #prints 1234 #here print @$r->{"a"} won't work #because this is a subscripted expression # now with list... my @x =(1,2,3,4); my $xref=\@x; print @$xref; #prints 1234 also #this works because there is no subscript
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: perl, mysql: "fetchrow_array failed: fetch() without execute()"
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 |