Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Clean Up MySQL Code

by astaines (Curate)
on Apr 21, 2003 at 09:42 UTC ( #251966=note: print w/ replies, xml ) Need Help??


in reply to Clean Up MySQL Code

Here's a slightly different approach - I create a load of SQL statements, put them in an array,

foreach my $sql (@sql) { unless ($sth=run_sql($sql)){ die "Failed in processing \"".$sql."\"\n"; } } #Use them like this... my $result = $sth->fetchall_arrayref;

and then run them using this subroutine -

# #run_sql # subroutine that does all of the work # sub run_sql{ my $sql = shift; my $sth = $dbh->prepare($sql); if (!$sth) { die "Error:" . $dbh->errstr ." while preparing ".$sql."\n"; } if (!$sth->execute) { die "Error:" . $sth->errstr ." while executing ".$sql."\n"; } return $sth; } # run_sql

The idea here is that I like to pass statement handles around ($sth), which I can then do whatever I want with. I find this much more flexible than passing result sets around. YMMV!

Happpy Easter,

--
Anthony Staines


Comment on Re: Clean Up MySQL Code
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://251966]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-07-22 18:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (126 votes), past polls