Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: MySQL and Perl - Shorthand

by Zaxo (Archbishop)
on Sep 21, 2002 at 03:26 UTC ( [id://199696]=note: print w/replies, xml ) Need Help??


in reply to MySQL and Perl - Shorthand

What you want is:

my ($the_name) = $dbh->selectrow_array( "SELECT the_name FROM the_table WHERE id=3");
but if you ever want to know another id, you're better off with:
$sth = $db->prepare("SELECT the_name FROM the_table WHERE id=?"); $sth->execute(3); my ($the_name) = $sth->fetchrow_array;

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: MySQL and Perl - Shorthand
by broquaint (Abbot) on Sep 21, 2002 at 13:06 UTC
    This
    $sth = $db->prepare("SELECT the_name FROM the_table WHERE id=?"); $sth->execute(3); my ($the_name) = $sth->fetchrow_array;
    Can be converted into this
    my ($the_name) = $dbh->selectrow_array(<<SQL, undef, 3); SELECT the_name FROM the_table WHERE id = ? SQL
    Although it always feels a little weird using selectrow_array for a single value. But I guess that's what abstraction layers are for :)
    HTH

    _________
    broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found