Could anyone advise as to why this script doesn't work:
#$dbh->do("create table terms (id INTEGER not NULL,
# term TEXT,tree TEXT, parent_id INTEGER,left_id
# int,right_id int,PRIMARY KEY (id))"
#
# );
#$dbh->do(qq| INSERT INTO terms VALUES (1,"ANATOMY BODY REGIONS","A01"
+,"1","1","8")|);
#$dbh->do(qq| INSERT INTO terms VALUES (2,"ABDOMEN","A01.047","1","2",
+"")|);
#$dbh->do(qq| INSERT INTO terms VALUES (3,"AXILA","A01.133","1","","")
+|);
#$dbh->do(qq| INSERT INTO terms VALUES (4,"EXTREMITIES","A01.378","1",
+"","")|);
#$dbh->do(qq| INSERT INTO terms VALUES (5,"ARM","A01.378.209","4","","
+")|);
#$dbh->do(qq| INSERT INTO terms VALUES (6,"ELBOW","A01.378.209.235","5
+","","")|);
#$dbh->do(qq| INSERT INTO terms VALUES (7,"HAND","A01.378.209.455","5"
+,"","")|);
#$dbh->do(qq| INSERT INTO terms VALUES (8,"FINGERS","A01.378.209.455.4
+30","7","","")|);
my $result= $dbh->prepare("SELECT id FROM terms WHERE parent_id = ?");
my $left = $dbh->prepare("UPDATE terms SET left_id=? WHERE id = ?");
my $right= $dbh->prepare("UPDATE terms SET left_id=? WHERE id = ?");
my $root =1;
my $counter = 1;
rebuild_tree($root);
sub rebuild_tree{
my $idy = shift;
$left->execute($ctr++,$idy);
$result->execute($idy);
while (my $idy = $result->fetchrow_hashref()) {
$idy = $i->{id};
rebuild_tree($idy);
}
$right->execute($ctr++,$idy);
}#end of sub
The error message I get is:
DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at s
+et_depth1.
pl line 67.
DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at s
+et_depth1.
pl line 67.
When I put all the prepare statements in the rebuild_tree sub, the results are not right. Anything wrong with the recursive method or is it a problem with my scoping? Any help would be much appreciated. I am trying to build a nested set database to access some hierarchical data.
I am using MySQL as my back-end database.