Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Monks who also work in PHP, help me upgrade my SQL code?

by Cody Fendant (Friar)
on Feb 28, 2013 at 00:18 UTC ( #1020978=perlquestion: print w/replies, xml ) Need Help??
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

This is probably pretty primitive for Perl programming, but I code my SQL like this:

$sth = $db_handle->prepare("select foo from bar where id = ?") or die( $db_handle->errstr ); $id = 17; ## or whatever $sth->execute( $id ) or die ( $sth->errstr() ); $baz = $sth->fetchrow_hashref();

I'm working more and more in PHP in a current job and I see nothing like that in the code I'm working with, no binding, just raw SQL commands constructed by variable/string concatenation and fed direct to mysql_query().

What's the professional way to do this in PHP?

Replies are listed 'Best First'.
Re: Monks who also work in PHP, help me upgrade my SQL code?
by Gangabass (Vicar) on Feb 28, 2013 at 04:18 UTC
Re: Monks who also work in PHP, help me upgrade my SQL code? (bobby-tables)
by Anonymous Monk on Feb 28, 2013 at 05:11 UTC
Re: Monks who also work in PHP, help me upgrade my SQL code?
by tobyink (Abbot) on Feb 28, 2013 at 07:56 UTC

    PDO.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1020978]
help
Chatterbox?
[choroba]: Didn't fight?
[erix]: ganesh in musht?
[LanX]: as a monotheist he would fight other problems
LanX succesfully trolled the CB into religion and leaves now! :)
[erix]: looking for his navel
[choroba]: Cleansing of the Temple
[zentara]: Unicorns are not conceived, they are created. Unicorns don't want another life. :-)
[erix]: you go check your data LanX :P
[Your Mother]: marto++ (me as well)
[zentara]: choroba I stand corrected, I guess Jesus killed a tree once too.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2017-03-30 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (361 votes). Check out past polls.