in reply to Looping through a subrouting

(@fer) = find_all_categories(); sub find_all_categories { $id = shift; if($id) { $sthm = $dbh->prepare_cached("SELECT * FROM category WHERE id=?"); $sthm->execute($id) or die $dbh->errstr; } else { $sthm = $dbh->prepare("SELECT * FROM category"); $sthm->execute or die $dbh->errstr; } while (@hi = $sthm->fetchrow_array) { if($hi[2] eq "0") { push(@env, @hi[0]) } else { $a = find_all_categories($slog[0]); $i += $hi[3]; $i + $a; } } push(@env,$i); return(@env); }
Yea im getting this little error

Can't call method "prepare" on an undefined value at cart.pm line 1612.

Replies are listed 'Best First'.
Re: Re: Looping through a subrouting
by dsalada (Scribe) on Jul 29, 2002 at 14:14 UTC
    It would seem that the function can't "see" $dbh. Did you create $dbh using my? If so, $dbh is out of scope. You'll need to pass it to the function as well along with $id.