in reply to MySQL and Perl - Shorthand

I use only one sub to run simple SQL:

sub runSQL { my $sql = shift; if ($sql =~ /^select/i) { my $sth = $dbh->prepare($sql); if (!$sth) { die "Error:" . $dbh->errstr . " :: $sql\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr . " :: $sql\n"; } my @ret; while (my $ref = $sth->fetchrow_hashref()) { push @ret, $ref; } $sth->finish(); return \@ret; } elsif ($sql =~ /^(insert|update|delete)/i) { if (!($dbh->do($sql))) { die "Error:" . $dbh->errstr . " :::: $sql\n"; } } }
and I get a reference to an array of hashes that holds values of SELECTS..
He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: Re: MySQL and Perl - Shorthand
by chromatic (Archbishop) on Sep 22, 2002 at 01:28 UTC

    Pass @_ to execute() and you can use placeholders. Handy. (I'd also use a prefixed unless, but that's just me.)