Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by dsb (Chaplain)
on Jan 24, 2001 at 03:01 UTC ( [id://53834]=note: print w/replies, xml ) Need Help??


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

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 Re: 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://53834]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found