Ruby MySQL INSERT variable

J

Justin To

k = "50"

my = Mysql::new("localhost", "root", "pass", "table")
my.query("INSERT INTO table VALUES('2008-05', #{k}, 324)")

/Class.rb:212:in `query': Unknown column '50' in 'field list'
(Mysql::Error)

How do I insert a variable into a row?

Thanks
 
B

ben baka

[Note: parts of this message were removed to make it a legal post.]

Well, i solved this by bringing ( ' ' ) around the #{k}. Thus your code is
likely to become like this,
my = Mysql::new("localhost", "root", "pass", "table")
my.query("INSERT INTO table VALUES('2008-05', '#{k}', 324)")

Hope it solves it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top