Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ruby MySQL INSERT variable

108 views
Skip to first unread message

Justin To

unread,
Jul 1, 2008, 5:42:03 PM7/1/08
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
--
Posted via http://www.ruby-forum.com/.

ben baka

unread,
Jul 2, 2008, 7:21:25 AM7/2/08
to
[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.

On 7/1/08, Justin To <te...@hotmail.com> wrote:
>
> 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
> --
> Posted via http://www.ruby-forum.com/.
>
>


--
--Ben Baka
Blog : http://benjaminbaka.wordpress.com/

0 new messages