in reply to MySQL and Perl - Shorthand
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"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: MySQL and Perl - Shorthand
by chromatic (Archbishop) on Sep 22, 2002 at 01:28 UTC |