Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Databases made easy

by Tanktalus (Canon)
on Apr 03, 2011 at 02:07 UTC ( #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 :-)

Comment on Re: Databases made easy
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2015-11-29 07:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (749 votes), past polls