Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Answer: What are placeholders in DBI, and why would I want to use them?

( #53834=categorized answer: print w/ replies, xml ) Need Help??

Q&A > database programming > What are placeholders in DBI, and why would I want to use them? contributed by dsb

Placeholders are just what they sound like. They hold the place in an SQL query for a SCALAR variable from somewhere else in the script to be plugged in. EX:
#! /usr/bin/perl use DBI; print "Enter the city you live in: "; chomp( $city = <STDIN> ); print "Enter the state you live in: "; chomp( $state = <STDIN> ); $dbh = DBI->connect(your db info here); $sth = $dbh->prepare( "SELECT name WHERE city = ? AND state = ?" ); $sth->execute( $city, $state );
In this code the first placeholder(?) would be filled with $city and the second would be filled with $state. They are filled in the order that the variables appear as arguments to the 'execute()' function. -kel

Comment on Answer: What are placeholders in DBI, and why would I want to use them?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-01 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls