Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: MySQL and Perl - Shorthand

by dws (Chancellor)
on Sep 21, 2002 at 04:14 UTC ( [id://199702]=note: print w/replies, xml ) Need Help??


in reply to MySQL and Perl - Shorthand

Everything is working fine, but I can't help but stare at the lengths I have to go through when I want to get a single value from the database.

If four statements strikes you as being a great length, then hide the length by wraping it up in a subroutine.

sub the_name { my $id = shift; my $sth = $db->prepare("select the_name from table where id = ?" +); $sth->execute($id); my ($the_name) = $sth->fetchrow_array(); $sth->finish(); return $the_name; }
then, you get the simplicity of   print the_name(3);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-18 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found