Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Databases made easy

by Tanktalus (Canon)
on Apr 03, 2011 at 02:07 UTC ( [id://897142]=note: print w/replies, xml ) Need Help??


in reply to Databases made easy

Tutorials on DBI are definitely needed and welcome - though I'd like to point out that any tutorial that doesn't use placeholders is likely doing a disservice. It doesn't take much more code to use placeholders, and helps newbies get used to them. In working with a number of developers over the years, in multiple languages, including some developers who don't merely write code against database but actually write databases, I see too many of them not using placeholders. Sometimes, as in your example, it doesn't matter. Sometimes they start putting user input directly into their SQL.

It doesn't hurt (much) to use placeholders for constant values, but it shows how it's done so that people following your (otherwise excellent and useful) example know how to interpolate their variables into their SQL (by not interpolating). For those new to using databases, it might seem obvious to say my $sql = qq{SELECT name, age, FROM People WHERE name LIKE '%$suffix' AND age < $maxage}; just based on your example. If, however, your example were using placeholders, it would merely seem obvious to replace the bound values with the variables they want to use. I've had to explain this to three different co-workers in the last year alone.

Thanks for the example :-)

Log In?
Username:
Password:

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

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

    No recent polls found