Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
my $sql = "SELECT * from shop_items"; my $sth = $dbh->prepare($sql); $sth->execute; while (my $hash_ref = $sth->fetchrow_hashref) { # bla bla bla }
I'm sure that's not quite right, but you get the drift of my thinking. Is this a good way to get rid of all those sections?while(my $hash_ref = fetch_data("SELECT * FROM shop_items")) { # bla bla bla } # SUBROUTINE FOR ALL CALLS sub fetch_data { my $sql = @_; my $sth = $dbh->prepare($sql); $sth->execute; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Clean Up MySQL Code
by Juerd (Abbot) on Apr 20, 2003 at 15:36 UTC | |
|
Re: Clean Up MySQL Code
by DrManhattan (Chaplain) on Apr 20, 2003 at 15:31 UTC | |
|
Re: Clean Up MySQL Code
by astaines (Curate) on Apr 21, 2003 at 09:42 UTC |