Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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?
[Corion]: hippo: Yeah, but at least two years ago, it still was close enough to 20% cut
[Corion]: But I have a very positive experience with a four day workweek and a three day weekend. I can't easily go back though to full money.
[Corion]: That is easy without having to pay for a house, a wife or children though. If I had any of these, or any two of these, the decision wouldn't be that easy.
[ambrus]: wait. I understand no wife and children, but how do you not have to pay for a house?
[hippo]: I had a low-paid job about 20 years ago and seriously considered going down to a 3-day week. Would have worked 60% of the time for about 80% of the cash.
[Corion]: ambrus: Well, I pay rent, but don't own a house with variable/ unforeseeable costs
[hippo]: The thesholds/benefits balance at the time was nuts.
[hippo]: But that doesn't last because, you know ... politicians. :(

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-09-21 15:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (249 votes). Check out past polls.

    Notices?