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

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

by Cody Fendant (Pilgrim)
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?

Comment on Monks who also work in PHP, help me upgrade my SQL code?
Download Code
Re: Monks who also work in PHP, help me upgrade my SQL code?
by Gangabass (Priest) 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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (12)
As of 2014-09-30 14:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (374 votes), past polls