# Newbie question eruby dbi

**URL:** <https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514>\
**Category:** Ruby\
**Created:** [February 22, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514 "2007-02-22T21:59:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 22, 2007, 9:59pm UTC](https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514/1 "2007-02-22T21:59:49Z")

</div>

Hi List  
I’ve spent the last couple days doing tutorials and so far I’m loving  
Ruby. My main function will be to use eruby on a web site.

I’ve been able to get many things working but one I’m stumped on one so  
I’m hoping someone can point me in the right direction.

I’m trying to use an ENV variable in a where statement as shown in the  
sample below. The problem is as soon as I use “” or ‘’ around my var  
username the var stops working as a var. I know this must be so simple  
that the obvious is escaping me (it does work when I put a username in  
manually).

Pleaseeeeeeee help 🙂

username = ENV[‘REMOTE\_USER’]

sth = dbh.execute(‘select grp from member where username like  
“username”’)  
while row=sth.fetch do  
printf “%s”, row[0]  
end  
sth.finish

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 22, 2007, 10:07pm UTC](https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514/2 "2007-02-22T22:07:51Z")

</div>

username = ENV[‘REMOTE\_USER’]

sth = dbh.execute(‘select grp from member where username like  
“#{username}”’)  
while row=sth.fetch do  
printf “%s”, row[0]  
end  
sth.finish

Good luck

Check the RubyMentor project:  
[http://rubymentor.rubyforge.org/wiki/wiki.pl](http://rubymentor.rubyforge.org/wiki/wiki.pl)

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 22, 2007, 10:26pm UTC](https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514/3 "2007-02-22T22:26:55Z")

</div>

Thanks!  
This works great!

Regards,  
Peter

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 22, 2007, 10:10pm UTC](https://www.ruby-forum.com/t/newbie-question-eruby-dbi/86514/4 "2007-02-22T22:10:53Z")

</div>

I think the query needs to be in double quotes to invoke string  
interpolation.

sth = dbh.execute(“select grp from member where username like  
‘#{username}’”)

SonOfLilit wrote:

> >

–  
Jeffery S. Swensen | Software Engineer  
Lextranet | 107 Union Wharf | Boston, MA 02109  
[http://www.lextranet.com](http://www.lextranet.com)  
(617) 227 4469 Extension 234  
removed\_email\_address@domain.invalid

THE INFORMATION IN THIS MESSAGE IS INTENDED ONLY FOR THE PERSONAL AND  
CONFIDENTIAL USE OF THE DESIGNATED RECIPIENTS NAMED ABOVE AND MAY  
CONTAIN LEGALLY PRIVILEGED INFORMATION. If the reader of this message is  
not the intended recipient or an agent responsible for delivering it to  
the intended recipient, you are hereby notified that you have received  
this document in error, and that any review, dissemination, distribution  
or copying of this message is strictly prohibited. If you have received  
this communication in error, please notify us immediately by telephone  
at 617-227-4469 Ext. 200. Thank you.
