Reputation: 7
When I try to connect to database via Ruby I'm getting this error :
conn.rb:16:in `<main>': undefined method `query=' for #<Mysql2::Client:0x2ee5190> (NoMethodError)
Did you mean? query
_query
My code is :
require 'mysql2'
connection = Mysql2::Client.new(:host => "localhost", :username => "root",:password => "",:database => "ruby")
result = connection.query = ("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")
Seems that everything is working until this line
result = connection.query = ("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")
I'm looking for someone who can help.
Upvotes: 1
Views: 54
Reputation: 30056
The error message is pretty clear: it does not exist a query=
method, but query
does. Try
result = connection.query("INSERT INTO datacheck(#{info.keys}) VALUES #{info.values}")
Upvotes: 2