467,146 Members | 1,013 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

help me for writing query in perl

hi....

i want to write the query
select * from user where name = "richard"; in perl

the string richard i have taken that in the variable $name.

i have written the query as below
Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh -> prepare('select * from user where name = "$name"');
  2.  
is this correct way of writing in perl?
Oct 1 '08 #1
  • viewed: 1174
Share:
1 Reply
Expert 100+
hi....
$sth = $dbh -> prepare('select * from user where name = "$name"');
In Perl, " " interpolates variables, ' ' doesn't, so putting a " " inside a ' ' won't cause the variables to be read. Try this instead:

Expand|Select|Wrap|Line Numbers
  1. $sth = $dbh->prepare("SELECT * FROM user WHERE name ='$name' ");
  2. #or, if you need double quotes in the query:
  3. $sth = $dbh->prepare("SELECT * FROM user WHERE name = \"$name\"");
  4. #or
  5. $sth = $dbh->prepare('SELECT * FROM user WHERE name = "' . $name . '"');
  6.  
Hope this helps.
Oct 1 '08 #2

Post your reply

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

Similar topics

7 posts views Thread by Dennis Roberts | last post: by
reply views Thread by pptran | last post: by
reply views Thread by Mike Chirico | last post: by
11 posts views Thread by olobraecky | last post: by
2 posts views Thread by geniuskanwal | last post: by
4 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.