using ruby variables with ruby/mysql

Mer Gilmartin wrote:

How do you put whats in a variable into a column in a ruby/mysql database?

I thought you could just put the variable name in an INSERT statement?

but '@mytext' puts in @mydata literally into the db. and @mytext gives an error message. I also tried mytext

sample code res = dbh.query("INSERT INTO word (u, up, temp) VALUES('check', 'check', @mytext)")

tags: ruby/mysql, variables, ruby, databases

-- Posted via http://www.ruby-forum.com/.

"#{@mytext}" will substitute the value of @mytext into the string. Note that this only works for double quoted strings...

_Kevin

Mer Gilmartin wrote:

> "#{@mytext}" will substitute the value of @mytext into the string. > Note that this only works for double quoted strings... > > _Kevin

Sorry, what do you mean?

I want to put the variable mytest's contents into a database. The contents of the variable wouldnt have any quotes on them.

Do you mean I used "#{@mytext}" in the insert statement?

-- Posted via http://www.ruby-forum.com/.

like this... res = dbh.query("INSERT INTO word (u, up, temp) VALUES('check', 'check', #{@mytext})")

although I'd wager that since you aren't using ActiveRecord that there is probably a much easier way to accomplish your goal

_Kevin