Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 rifling through the Monastery: (11)
As of 2014-12-18 19:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls