Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old August 8th, 2008, 05:14 AM
Member
 
Join Date: Jul 2008
Posts: 41
Default perl DBI doubt

Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare("select count(*) from test where status = 1 and name= '$name");
  2.     $sth->execute();
How do I change the above statement so that the variable $name can be avoided inside a prepare statement as it is a vraible.

Thanks.
Reply
  #2  
Old August 8th, 2008, 05:24 AM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 837
Default

What do you mean by "avoided"?

--Kevin
Reply
  #3  
Old August 8th, 2008, 05:33 AM
Member
 
Join Date: Jul 2008
Posts: 41
Default

How to pass variables in sql prepared statement? Is there any other means of doing it?
Reply
  #4  
Old August 8th, 2008, 05:37 AM
Member
 
Join Date: Jul 2008
Posts: 41
Default

Yes Thx. I could do it as below:

Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare("select count(*) from test where status = 1 and name=?");
  2. $sth->execute($name);
Reply
  #5  
Old August 8th, 2008, 05:38 AM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 837
Default

Placeholders and Bind Values

Expand|Select|Wrap|Line Numbers
  1. my $sql = $dbh->prepare(q{SELECT name FROM test  WHERE user_id = (?)});
  2.    $sql->execute($user_id);
--Kevin
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles