in reply to I still haven't found any solution to DBD::mysql::st fetchrow_array failed: fetch() without execute()
while (my @names = $sth->fetchrow_array){ $sth = $dbh->prepare("INSERT INTO names (name) VALUES (?)"); $sth->execute($names[0]); $count++; #THIS IS LINE 27. }
You're clobbering your $sth. You have one to select (the while condition) and one to write (inside the while loop). Your selector is being overwritten, and replaced, by your writer. Try a new name for the inner $sth.
Update- you should also move the writer out of the loop. You only need to prepare it once and you can reuse it all you like.
my $insert_sth = $dbh->prepare("INSERT INTO names (name) VALUES (?)"); while (my @names = $sth->fetchrow_array){ $insert_sth->execute($names[0]); } $sth->finish(); $insert_sth->finish();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: I still haven't found any solution to DBD::mysql::st fetchrow_array failed: fetch() without execute()
by Furple (Novice) on Dec 11, 2008 at 19:33 UTC |