By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

perl DBI doubt

P: 89
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.
Aug 8 '08 #1
Share this Question
Share on Google+
4 Replies


eWish
Expert 100+
P: 971
What do you mean by "avoided"?

--Kevin
Aug 8 '08 #2

P: 89
How to pass variables in sql prepared statement? Is there any other means of doing it?
Aug 8 '08 #3

P: 89
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);
Aug 8 '08 #4

eWish
Expert 100+
P: 971
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
Aug 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.