I use only one sub to run simple SQL:
and I get a reference to an array of hashes that holds values of SELECTS..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"; } } }
In reply to Re: MySQL and Perl - Shorthand
by Chady
in thread MySQL and Perl - Shorthand
by mt2k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |